~kubuntu-members/korundum/4.11

« back to all changes in this revision

Viewing changes to korundum/modules/akonadi/examples/akonamail/mainwidget.rb

  • Committer: Ian Monroe
  • Date: 2010-11-21 15:55:01 UTC
  • Revision ID: git-v1:c37670e4e3c59f5eb2ba112f5341a5e706217f6f
Split up Smoke into Qt and KDE directories. 
Move libsmoke stuff into the generator directory
Split up Ruby into qtruby and korundum directories

svn path=/trunk/KDE/kdebindings/ruby/; revision=1199320

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=begin
 
2
    Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
 
3
 
 
4
    This library is free software; you can redistribute it and/or modify it
 
5
    under the terms of the GNU Library General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or (at your
 
7
    option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful, but WITHOUT
 
10
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
12
    License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with self library; see the file COPYING.LIB.  If not, write to the
 
16
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
    02110-1301, USA.
 
18
=end
 
19
 
 
20
class MainWidget < Qt::Widget
 
21
 
 
22
  slots 'collectionClicked(Akonadi::Collection)',
 
23
        'itemActivated(QModelIndex)',
 
24
        'itemFetchDone(job)',
 
25
        'threadCollection()'
 
26
 
 
27
  def initialize(parent = nil)
 
28
    super(parent)
 
29
    @mainWindow = parent
 
30
    connect( @mainWindow, SIGNAL(:threadCollection),
 
31
             self, SLOT(:threadCollection) )
 
32
 
 
33
    layout = Qt::HBoxLayout.new(self)
 
34
 
 
35
    splitter = Qt::Splitter.new(Qt::Horizontal, self)
 
36
    layout.addWidget(splitter)
 
37
 
 
38
    # Left part, collection view
 
39
    @collectionList = Akonadi::CollectionView.new
 
40
    connect( @collectionList, SIGNAL('clicked(Akonadi::Collection)'),
 
41
             SLOT('collectionClicked(Akonadi::Collection)') )
 
42
    collectionDelegate = Akonadi::CollectionStatisticsDelegate.new(@collectionList)
 
43
    collectionDelegate.unreadCountShown = true  #For testing, should be toggleable columns eventually
 
44
    @collectionList.itemDelegate = collectionDelegate
 
45
    splitter.addWidget(@collectionList)
 
46
    # Filter the collection to only show the emails
 
47
    @collectionModel = Akonadi::CollectionStatisticsModel.new(self)
 
48
    @collectionProxyModel = Akonadi::CollectionFilterProxyModel.new(self) do |m|
 
49
      m.sourceModel = @collectionModel
 
50
      m.addMimeTypeFilter("message/rfc822")
 
51
    end
 
52
 
 
53
    # display collections sorted
 
54
    sortModel = Qt::SortFilterProxyModel.new(self) do |s|
 
55
      s.dynamicSortFilter = true
 
56
      s.sortCaseSensitivity = Qt::CaseInsensitive
 
57
      s.sourceModel = @collectionProxyModel
 
58
    end
 
59
 
 
60
    # Right part, message list + message viewer
 
61
    rightSplitter = Qt::Splitter.new(Qt::Vertical, self)
 
62
    splitter.addWidget( rightSplitter )
 
63
    @messageList = Qt::TreeView.new(self) do |l|
 
64
      l.dragEnabled = true
 
65
      l.selectionMode = Qt::AbstractItemView::ExtendedSelection
 
66
    end
 
67
    connect(@messageList, SIGNAL('clicked(QModelIndex)'), SLOT('itemActivated(QModelIndex)'))
 
68
    rightSplitter.addWidget(@messageList)
 
69
 
 
70
    @collectionList.model = sortModel
 
71
    @messageModel = Akonadi::MessageModel.new(self)
 
72
    @messageProxyModel = Akonadi::MessageThreaderProxyModel.new(self)
 
73
    @messageProxyModel.sourceModel = @messageModel
 
74
    @messageList.model = @messageProxyModel
 
75
 
 
76
    @messageView = Qt::TextEdit.new(self)
 
77
    rightSplitter.addWidget(@messageView)
 
78
 
 
79
    splitter.sizes = [200, 500]
 
80
    rightSplitter.sizes = [300, 200]
 
81
  end
 
82
 
 
83
  def collectionClicked(collection)
 
84
    @currentCollection = collection
 
85
    @messageModel.collection = Akonadi::Collection.new(@currentCollection)
 
86
  end
 
87
 
 
88
  def itemActivated(index)
 
89
    item = @messageModel.itemForIndex(@messageProxyModel.mapToSource(index))
 
90
 
 
91
    if !item.valid?
 
92
      return
 
93
    end
 
94
 
 
95
    job = Akonadi::ItemFetchJob.new(item, self)
 
96
    job.fetchScope.fetchFullPayload
 
97
    connect(job, SIGNAL('result(KJob*)'), SLOT('itemFetchDone(KJob*)'))
 
98
    job.start()
 
99
  end
 
100
 
 
101
  def itemFetchDone(job)
 
102
    fetch = job
 
103
    if job.error
 
104
      puts "Mail fetch failed: #{job.errorString}"
 
105
    elsif fetch.items.empty?
 
106
      puts "No mail found!"
 
107
    else
 
108
      item = fetch.items.first
 
109
      @messageView.plainText = item.payloadData
 
110
    end
 
111
  end
 
112
 
 
113
  def threadCollection
 
114
    return if @currentCollection.nil?
 
115
    a = @currentCollection.attribute(Akonadi::Collection::AddIfMissing)
 
116
    a.deserialize(Qt::ByteArray.new("sort"))
 
117
    job = Akonadi::CollectionModifyJob.new(@currentCollection)
 
118
    if !job.exec
 
119
      puts "Unable to modify collection"
 
120
    end
 
121
  end
 
122
end
 
123
 
 
124
 
 
125