2
Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
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.
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.
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
20
class MainWidget < Qt::Widget
22
slots 'collectionClicked(Akonadi::Collection)',
23
'itemActivated(QModelIndex)',
27
def initialize(parent = nil)
30
connect( @mainWindow, SIGNAL(:threadCollection),
31
self, SLOT(:threadCollection) )
33
layout = Qt::HBoxLayout.new(self)
35
splitter = Qt::Splitter.new(Qt::Horizontal, self)
36
layout.addWidget(splitter)
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")
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
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|
65
l.selectionMode = Qt::AbstractItemView::ExtendedSelection
67
connect(@messageList, SIGNAL('clicked(QModelIndex)'), SLOT('itemActivated(QModelIndex)'))
68
rightSplitter.addWidget(@messageList)
70
@collectionList.model = sortModel
71
@messageModel = Akonadi::MessageModel.new(self)
72
@messageProxyModel = Akonadi::MessageThreaderProxyModel.new(self)
73
@messageProxyModel.sourceModel = @messageModel
74
@messageList.model = @messageProxyModel
76
@messageView = Qt::TextEdit.new(self)
77
rightSplitter.addWidget(@messageView)
79
splitter.sizes = [200, 500]
80
rightSplitter.sizes = [300, 200]
83
def collectionClicked(collection)
84
@currentCollection = collection
85
@messageModel.collection = Akonadi::Collection.new(@currentCollection)
88
def itemActivated(index)
89
item = @messageModel.itemForIndex(@messageProxyModel.mapToSource(index))
95
job = Akonadi::ItemFetchJob.new(item, self)
96
job.fetchScope.fetchFullPayload
97
connect(job, SIGNAL('result(KJob*)'), SLOT('itemFetchDone(KJob*)'))
101
def itemFetchDone(job)
104
puts "Mail fetch failed: #{job.errorString}"
105
elsif fetch.items.empty?
106
puts "No mail found!"
108
item = fetch.items.first
109
@messageView.plainText = item.payloadData
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)
119
puts "Unable to modify collection"