|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "fbsearchview.h" |
|
19 #include "enginewrapper.h" |
|
20 #include "notifications.h" |
|
21 |
|
22 #include <HbView> |
|
23 #include <HbDataForm> |
|
24 #include <HbDataFormModel> |
|
25 #include <HbDataFormModelItem> |
|
26 #include <HbAction> |
|
27 #include <HbListWidget> |
|
28 #include <HbListWidgetItem> |
|
29 #include <HbDialog> |
|
30 #include <HbToolBar> |
|
31 #include <HbProgressDialog> |
|
32 |
|
33 #include <QtGui> |
|
34 #include <QDir> |
|
35 #include <QFileInfo> |
|
36 |
|
37 const QStringList RECURSEMODES = (QStringList() << "Non-recursive" << "Recursive"); |
|
38 const QString AcceptActionText = "Search"; |
|
39 const QString RejectActionText = "Cancel"; |
|
40 |
|
41 |
|
42 FbSearchView::FbSearchView(QGraphicsItem *parent) |
|
43 : HbView(parent), |
|
44 mAttributes(), |
|
45 mResults(), |
|
46 mForm(0), |
|
47 mSearchFileNameItem(0), |
|
48 mWildCardItem(0), |
|
49 mHasString(0), |
|
50 mRecurse(0), |
|
51 mMinSize(0), |
|
52 mMaxSize(0), |
|
53 mMinDate(0), |
|
54 mMaxDate(0), |
|
55 mPath(), |
|
56 mProgressDialog(0) |
|
57 { |
|
58 // Set title and add this view to main window |
|
59 setTitle("Search"); |
|
60 |
|
61 // Override back navigation action |
|
62 HbAction *leaveViewAction = new HbAction(Hb::BackNaviAction, this); |
|
63 connect(leaveViewAction, SIGNAL(triggered()), this, SLOT(reject())); |
|
64 setNavigationAction(leaveViewAction); |
|
65 |
|
66 initDataForm(); |
|
67 createToolbar(); |
|
68 } |
|
69 |
|
70 FbSearchView::~FbSearchView() |
|
71 { |
|
72 } |
|
73 |
|
74 void FbSearchView::initDataForm() { |
|
75 mForm = new HbDataForm(/*HbFormView::ModeEdit,*/ this); |
|
76 HbDataFormModel *model = new HbDataFormModel(); |
|
77 |
|
78 mSearchFileNameItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
79 mSearchFileNameItem->setLabel("Search dir: "); |
|
80 |
|
81 mWildCardItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
82 mWildCardItem->setLabel("Wildcards: "); |
|
83 |
|
84 mHasString = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
85 mHasString->setLabel("Has string: "); |
|
86 |
|
87 mRecurse = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem); |
|
88 mRecurse->setLabel("Recurse: "); |
|
89 mRecurse->setContentWidgetData("items", RECURSEMODES); |
|
90 |
|
91 mMinSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
92 mMinSize->setLabel("Min size: "); |
|
93 |
|
94 mMaxSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
95 mMaxSize->setLabel("Max size: "); |
|
96 |
|
97 mMinDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
98 mMinDate->setLabel("Min date: "); |
|
99 mMinDate->setContentWidgetData("text", "01/01/1980"); |
|
100 |
|
101 mMaxDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
102 mMaxDate->setLabel("Max date: "); |
|
103 mMaxDate->setContentWidgetData("text", "31/12/2060"); |
|
104 |
|
105 model->appendDataFormItem(mSearchFileNameItem); |
|
106 model->appendDataFormItem(mWildCardItem); |
|
107 model->appendDataFormItem(mHasString); |
|
108 model->appendDataFormItem(mRecurse); |
|
109 model->appendDataFormItem(mMinSize); |
|
110 model->appendDataFormItem(mMaxSize); |
|
111 model->appendDataFormItem(mMinDate); |
|
112 model->appendDataFormItem(mMaxDate); |
|
113 mForm->setModel(model); |
|
114 |
|
115 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this); |
|
116 layout->addItem(mForm); |
|
117 setLayout(layout); |
|
118 } |
|
119 |
|
120 void FbSearchView::createToolbar() |
|
121 { |
|
122 HbToolBar *toolBar = new HbToolBar(this); |
|
123 HbAction *acceptAction = new HbAction(AcceptActionText); |
|
124 connect(acceptAction, SIGNAL(triggered()), this, SLOT(accept())); |
|
125 toolBar->addAction(acceptAction); |
|
126 |
|
127 HbAction *rejectAction = new HbAction(RejectActionText); |
|
128 connect(rejectAction, SIGNAL(triggered()), this, SLOT(reject())); |
|
129 toolBar->addAction(rejectAction); |
|
130 |
|
131 setToolBar(toolBar); |
|
132 } |
|
133 |
|
134 void FbSearchView::loadAttributes() |
|
135 { |
|
136 // set data: |
|
137 mSearchFileNameItem->setContentWidgetData("text", mPath); |
|
138 // mSearchFileNameItem->setContentWidgetData("text", mAttributes.mSearchDir); |
|
139 if (!mAttributes.mDefaultWildCard) { |
|
140 mWildCardItem->setContentWidgetData("text", mAttributes.mWildCards); |
|
141 } |
|
142 mHasString->setContentWidgetData("text", mAttributes.mTextInFile); |
|
143 |
|
144 mRecurse->setContentWidgetData("selected", mAttributes.mRecurse); |
|
145 |
|
146 mMinSize->setContentWidgetData("text", mAttributes.mMinSize); |
|
147 mMaxSize->setContentWidgetData("text", mAttributes.mMaxSize); |
|
148 |
|
149 mMinDate->setContentWidgetData("text", mAttributes.mMinDate); |
|
150 mMaxDate->setContentWidgetData("text", mAttributes.mMaxDate); |
|
151 } |
|
152 |
|
153 /** |
|
154 * Reads form items and saves values of them into member variable mAttributes |
|
155 */ |
|
156 void FbSearchView::readFormItems() |
|
157 { |
|
158 mAttributes.mSearchDir = mSearchFileNameItem->contentWidgetData("text").toString(); |
|
159 |
|
160 mAttributes.mDefaultWildCard = false; |
|
161 QString wildCard = mWildCardItem->contentWidgetData("text").toString(); |
|
162 if (wildCard.trimmed().isEmpty()) { |
|
163 wildCard = QString("*"); |
|
164 mAttributes.mDefaultWildCard = true; |
|
165 } |
|
166 mAttributes.mWildCards = wildCard; |
|
167 mAttributes.mTextInFile = mHasString->contentWidgetData("text").toString(); |
|
168 mAttributes.mMinSize = mMinSize->contentWidgetData("text").toInt(); |
|
169 mAttributes.mMaxSize = mMaxSize->contentWidgetData("text").toInt(); |
|
170 mAttributes.mMinDate = mMinDate->contentWidgetData("text").toDate(); |
|
171 mAttributes.mMaxDate = mMaxDate->contentWidgetData("text").toDate(); |
|
172 mAttributes.mRecurse = mRecurse->contentWidgetData("selected").toBool(); |
|
173 } |
|
174 |
|
175 void FbSearchView::open(const SearchAttributes &searchAttributes, const QString &path) |
|
176 { |
|
177 mPath = path; |
|
178 // get settings from engine; |
|
179 mAttributes = searchAttributes; |
|
180 // load file search attribute values from FB engine: |
|
181 loadAttributes(); |
|
182 } |
|
183 |
|
184 void FbSearchView::startFileSearch(EngineWrapper *engineWrapper) |
|
185 { |
|
186 // save form data values and set them as search attributes into FB engine. |
|
187 readFormItems(); |
|
188 engineWrapper->setFileSearchAttributes(mAttributes); |
|
189 |
|
190 bool err = engineWrapper->searchFiles(); |
|
191 |
|
192 // show results of file search: |
|
193 mResults = engineWrapper->getSearchResults(); |
|
194 |
|
195 QString noteMsg("%1 entries found"); |
|
196 Notifications::showInformationNote(noteMsg.arg(engineWrapper->itemCount())); |
|
197 } |
|
198 |
|
199 void FbSearchView::accept() |
|
200 { |
|
201 emit finished(true); |
|
202 } |
|
203 |
|
204 void FbSearchView::reject() |
|
205 { |
|
206 emit finished(false); |
|
207 } |