~ubuntu-branches/ubuntu/intrepid/bibletime/intrepid

« back to all changes in this revision

Viewing changes to bibletime/frontend/searchdialog/csearchresultview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
#include "csearchresultview.h"
 
13
 
 
14
#include "backend/cswordversekey.h"
 
15
 
 
16
#include "frontend/cdragdropmgr.h"
 
17
#include "frontend/cexportmanager.h"
 
18
 
 
19
#include "util/cresmgr.h"
 
20
 
 
21
//Qt includes
 
22
 
 
23
//KDE includes
 
24
#include <klocale.h>
 
25
#include <kaction.h>
 
26
#include <kpopupmenu.h>
 
27
 
 
28
namespace Search {
 
29
        namespace Result {
 
30
 
 
31
CSearchResultView::CSearchResultView(QWidget* parent, const char* name) :
 
32
        KListView(parent, name), m_module(0) {
 
33
        initView();
 
34
        initConnections();
 
35
}
 
36
 
 
37
CSearchResultView::~CSearchResultView() {}
 
38
 
 
39
/** Initializes the view of this widget. */
 
40
void CSearchResultView::initView() {
 
41
        addColumn(i18n("Results"));
 
42
        setFullWidth(true);
 
43
        
 
44
        setSorting(-1);
 
45
        setDragEnabled(true);
 
46
        setSelectionModeExt(KListView::Extended);
 
47
 
 
48
        //setup the popup menu
 
49
        m_popup = new KPopupMenu(this);
 
50
 
 
51
        m_actions.copyMenu = new KActionMenu(i18n("Copy..."), CResMgr::searchdialog::result::foundItems::copyMenu::icon, m_popup);
 
52
        m_actions.copyMenu->setDelayed(false);
 
53
        m_actions.copy.result = new KAction(i18n("Reference only"), KShortcut(0), this, SLOT(copyItems()), this);
 
54
        m_actions.copyMenu->insert(m_actions.copy.result);
 
55
        m_actions.copy.resultWithText = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(copyItemsWithText()), this);
 
56
        m_actions.copyMenu->insert(m_actions.copy.resultWithText);
 
57
        m_actions.copyMenu->plug(m_popup);
 
58
 
 
59
        m_actions.saveMenu = new KActionMenu(i18n("Save..."),CResMgr::searchdialog::result::foundItems::saveMenu::icon, m_popup);
 
60
        m_actions.saveMenu->setDelayed( false );
 
61
        m_actions.save.result = new KAction(i18n("Reference only"), KShortcut(0), this, SLOT(saveItems()), this);
 
62
        m_actions.saveMenu->insert(m_actions.save.result);
 
63
        m_actions.save.resultWithText = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(saveItemsWithText()), this);
 
64
        m_actions.saveMenu->insert(m_actions.save.resultWithText);
 
65
        m_actions.saveMenu->plug(m_popup);
 
66
 
 
67
        m_actions.printMenu = new KActionMenu(i18n("Print..."),CResMgr::searchdialog::result::foundItems::printMenu::icon, m_popup);
 
68
        m_actions.printMenu->setDelayed(false);
 
69
        m_actions.print.result = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(printItems()), this);
 
70
        m_actions.printMenu->insert(m_actions.print.result);
 
71
        m_actions.printMenu->plug(m_popup);
 
72
}
 
73
 
 
74
/** No descriptions */
 
75
void CSearchResultView::initConnections() {
 
76
        //  connect(this, SIGNAL(executed(QListViewItem*)),
 
77
        //   this, SLOT(executed(QListViewItem*)));
 
78
        connect(this, SIGNAL(currentChanged(QListViewItem*)),
 
79
                        this, SLOT(executed(QListViewItem*)));
 
80
 
 
81
        connect(this, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)),
 
82
                        this, SLOT(showPopup(KListView*, QListViewItem*, const QPoint&)));
 
83
}
 
84
 
 
85
/** Setups the list with the given module. */
 
86
void CSearchResultView::setupTree(CSwordModuleInfo* m) {
 
87
        clear();
 
88
        
 
89
        if (!m) {
 
90
                return;
 
91
        }
 
92
 
 
93
        m_module = m;
 
94
 
 
95
        sword::ListKey& result = m->searchResult();
 
96
        const int count = result.Count();
 
97
        if (!count) {
 
98
                return;
 
99
        }
 
100
 
 
101
        setUpdatesEnabled(false);
 
102
 
 
103
        QListViewItem* oldItem = 0;
 
104
        KListViewItem* item = 0;
 
105
        for (int index = 0; index < count; index++) {
 
106
                item = new KListViewItem(this, oldItem);
 
107
                item->setText(0, QString::fromUtf8(result.GetElement(index)->getText()));
 
108
                
 
109
                oldItem = item;
 
110
        }
 
111
 
 
112
        setUpdatesEnabled(true);
 
113
 
 
114
        setSelected(firstChild(), true);
 
115
        executed(currentItem());
 
116
}
 
117
 
 
118
void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, QStringList* vList) {
 
119
   clear();
 
120
   if (!m) {
 
121
      return;
 
122
   }
 
123
 
 
124
   m_module = m;
 
125
 
 
126
   if (vList->count() <= 0) {
 
127
      return;
 
128
   }
 
129
 
 
130
   setUpdatesEnabled(false);
 
131
 
 
132
   KListViewItem* oldItem = 0;
 
133
   KListViewItem* item = 0;
 
134
 
 
135
   for ( QStringList::Iterator it = vList->begin(); it != vList->end(); ++it ) {
 
136
      item = new KListViewItem(this, oldItem);
 
137
      item->setText(0, (*it));
 
138
          
 
139
      oldItem = item;
 
140
   }
 
141
   
 
142
   setUpdatesEnabled(true);
 
143
 
 
144
   setSelected(firstChild(), true);
 
145
   executed(currentItem());
 
146
}
 
147
 
 
148
/** Is connected to the signal executed, which is emitted when a mew item was chosen. */
 
149
void CSearchResultView::executed(QListViewItem* item) {
 
150
        //  Q_ASSERT(item);
 
151
        //  qWarning("executed");
 
152
        emit keySelected(item->text(0));
 
153
}
 
154
 
 
155
/** Reimplementation to show the popup menu. */
 
156
void CSearchResultView::showPopup(KListView*, QListViewItem*, const QPoint& point) {
 
157
        m_popup->exec(point);
 
158
}
 
159
 
 
160
/** No descriptions */
 
161
void CSearchResultView::printItems() {
 
162
        QPtrList<QListViewItem> items = selectedItems();
 
163
        CExportManager mgr(i18n("Print search result..."), true, i18n("Printing search result"));
 
164
 
 
165
        QStringList list;
 
166
        for (QListViewItem* k = items.first(); k; k = items.next()) {
 
167
                list.append( k->text(0) );
 
168
        };
 
169
        mgr.printKeyList( list, module(), CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults() );
 
170
}
 
171
 
 
172
/** No descriptions */
 
173
void CSearchResultView::saveItems() {
 
174
        CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
 
175
 
 
176
        CSwordModuleInfo* m = module();
 
177
        CSwordKey* k = 0;
 
178
        QPtrList<QListViewItem> items = selectedItems();
 
179
        QPtrList<CSwordKey> keys;
 
180
        for (QListViewItem* i = items.first(); i; i = items.next()) {
 
181
                k = CSwordKey::createInstance( m );
 
182
                k->key(i->text(0));
 
183
                keys.append( k );
 
184
        };
 
185
        mgr.saveKeyList( keys, CExportManager::Text, false);
 
186
 
 
187
        keys.setAutoDelete(true);
 
188
        keys.clear(); //delete all the keys we created
 
189
}
 
190
 
 
191
/** No descriptions */
 
192
void CSearchResultView::saveItemsWithText() {
 
193
        CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
 
194
 
 
195
        CSwordModuleInfo* m = module();
 
196
        CSwordKey* k = 0;
 
197
        QPtrList<QListViewItem> items = selectedItems();
 
198
        QPtrList<CSwordKey> keys;
 
199
        for (QListViewItem* i = items.first(); i; i = items.next()) {
 
200
                k = CSwordKey::createInstance( m );
 
201
                k->key(i->text(0));
 
202
                keys.append( k );
 
203
        };
 
204
        mgr.saveKeyList( keys, CExportManager::Text, true);
 
205
 
 
206
        keys.setAutoDelete(true);
 
207
        keys.clear(); //delete all the keys we created
 
208
}
 
209
 
 
210
/** No descriptions */
 
211
void CSearchResultView::copyItems() {
 
212
        CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
 
213
 
 
214
        CSwordModuleInfo* m = module();
 
215
        CSwordKey* k = 0;
 
216
        QPtrList<QListViewItem> items = selectedItems();
 
217
        QPtrList<CSwordKey> keys;
 
218
        for (QListViewItem* i = items.first(); i; i = items.next()) {
 
219
                k = CSwordKey::createInstance( m );
 
220
                k->key(i->text(0));
 
221
                keys.append( k );
 
222
        };
 
223
        mgr.copyKeyList( keys, CExportManager::Text, false);
 
224
 
 
225
        keys.setAutoDelete(true);
 
226
        keys.clear(); //delete all the keys we created
 
227
}
 
228
 
 
229
/** No descriptions */
 
230
void CSearchResultView::copyItemsWithText() {
 
231
        CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
 
232
 
 
233
        CSwordModuleInfo* m = module();
 
234
        CSwordKey* k = 0;
 
235
        QPtrList<QListViewItem> items = selectedItems();
 
236
        QPtrList<CSwordKey> keys;
 
237
        for (QListViewItem* i = items.first(); i; i = items.next()) {
 
238
                k = CSwordKey::createInstance( m );
 
239
                k->key(i->text(0));
 
240
                keys.append( k );
 
241
        };
 
242
        mgr.copyKeyList( keys, CExportManager::Text, true);
 
243
 
 
244
        keys.setAutoDelete(true);
 
245
        keys.clear(); //delete all the keys we created
 
246
}
 
247
 
 
248
/** Returns the module which is currently used. */
 
249
CSwordModuleInfo* const CSearchResultView::module() {
 
250
        return m_module;
 
251
}
 
252
 
 
253
QDragObject* CSearchResultView::dragObject() {
 
254
        //return a valid DragObject to make DnD possible!
 
255
 
 
256
        /*
 
257
        * First get all selected items and fill with them the dndItems list. The return the QDragObject we got from CDRagDropMgr
 
258
        */
 
259
        CDragDropMgr::ItemList dndItems;
 
260
 
 
261
        QPtrList<QListViewItem> items = selectedItems();
 
262
        for (items.first(); items.current(); items.next()) {
 
263
                dndItems.append( CDragDropMgr::Item(m_module->name(), items.current()->text(0), QString::null) ); //no description
 
264
        };
 
265
 
 
266
        return CDragDropMgr::dragObject(dndItems, viewport());
 
267
}
 
268
 
 
269
        } //end of namespace Search::Result
 
270
} //end of namespace
 
271