|
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 "searchview.h" |
|
19 #include "enginewrapper.h" |
|
20 |
|
21 #include <HbView> |
|
22 #include <HbMainWindow> |
|
23 |
|
24 #include <HbDataForm> |
|
25 #include <HbDataFormModel> |
|
26 #include <HbDataFormModelItem> |
|
27 #include <HbAction> |
|
28 #include <HbPushButton> |
|
29 #include <HbListWidget> |
|
30 #include <HbListWidgetItem> |
|
31 #include <HbDialog> |
|
32 #include <HbMenu> |
|
33 |
|
34 #include <QtGui> |
|
35 #include <QDir> |
|
36 #include <QFileInfo> |
|
37 #include <QProgressBar> |
|
38 |
|
39 |
|
40 const QStringList RECURSEMODES = (QStringList() << "Non-recursive" << "Recursive"); |
|
41 |
|
42 SearchView::SearchView(HbView &mainView, HbMainWindow &mainWindow, EngineWrapper &engineWrapper) |
|
43 : mMainWindow(mainWindow), |
|
44 mMainView(mainView), |
|
45 mEngineWrapper(engineWrapper), |
|
46 mAttributes(), |
|
47 mResults(), |
|
48 mForm(0), |
|
49 mSearchFileNameItem(0), |
|
50 mWildCardItem(0), |
|
51 mHasString(0), |
|
52 mRecurse(0), |
|
53 mMinSize(0), |
|
54 mMaxSize(0), |
|
55 mMinDate(0), |
|
56 mMaxDate(0), |
|
57 mPath() |
|
58 { |
|
59 } |
|
60 |
|
61 SearchView::~SearchView() |
|
62 { |
|
63 } |
|
64 |
|
65 void SearchView::open(const QString &path) |
|
66 { |
|
67 // Remove main view from main window |
|
68 mMainWindow.removeView(&mMainView); |
|
69 mMainWindow.addView(this); |
|
70 // Set title and add this view to main window |
|
71 setTitle("Search"); |
|
72 |
|
73 mForm = new HbDataForm(/*HbFormView::ModeEdit,*/ this); |
|
74 HbDataFormModel *model = new HbDataFormModel(); |
|
75 mPath = path; |
|
76 mSearchFileNameItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
77 mSearchFileNameItem->setLabel("Search dir: "); |
|
78 |
|
79 mWildCardItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
80 mWildCardItem->setLabel("Wildcards: "); |
|
81 |
|
82 mHasString = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
83 mHasString->setLabel("Has string: "); |
|
84 |
|
85 mRecurse = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem); |
|
86 mRecurse->setLabel("Recurse: "); |
|
87 mRecurse->setContentWidgetData("items", RECURSEMODES); |
|
88 |
|
89 mMinSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
90 mMinSize->setLabel("Min size: "); |
|
91 |
|
92 mMaxSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
93 mMaxSize->setLabel("Max size: "); |
|
94 |
|
95 mMinDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
96 mMinDate->setLabel("Min date: "); |
|
97 mMinDate->setContentWidgetData("text", "01/01/1980"); |
|
98 |
|
99 mMaxDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
|
100 mMaxDate->setLabel("Max date: "); |
|
101 mMaxDate->setContentWidgetData("text", "31/12/2060"); |
|
102 |
|
103 // load file search attribute values from FB engine: |
|
104 loadAttributes(); |
|
105 |
|
106 model->appendDataFormItem(mSearchFileNameItem); |
|
107 model->appendDataFormItem(mWildCardItem); |
|
108 model->appendDataFormItem(mHasString); |
|
109 model->appendDataFormItem(mRecurse); |
|
110 model->appendDataFormItem(mMinSize); |
|
111 model->appendDataFormItem(mMaxSize); |
|
112 model->appendDataFormItem(mMinDate); |
|
113 model->appendDataFormItem(mMaxDate); |
|
114 mForm->setModel(model); |
|
115 |
|
116 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this); |
|
117 |
|
118 HbPushButton* buttonSearch = new HbPushButton("Search"); |
|
119 buttonSearch->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); |
|
120 connect(buttonSearch, SIGNAL(clicked()), this, SLOT(startFileSearch())); |
|
121 |
|
122 HbPushButton* buttonCancel = new HbPushButton("Cancel"); |
|
123 buttonCancel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); |
|
124 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(backButtonClicked())); |
|
125 |
|
126 // Create widget and layout for buttons |
|
127 QGraphicsWidget *buttonsWidget = new QGraphicsWidget(this); |
|
128 QGraphicsGridLayout *gridLayout = new QGraphicsGridLayout(buttonsWidget); |
|
129 |
|
130 // add buttons to layout |
|
131 gridLayout->addItem(buttonSearch, 0, 0); |
|
132 gridLayout->addItem(buttonCancel, 0, 1); |
|
133 buttonsWidget->setLayout(gridLayout); |
|
134 // add form and buttons widget to list layout |
|
135 layout->addItem(mForm); |
|
136 layout->addItem(buttonsWidget); |
|
137 setLayout(layout); |
|
138 // about to close connect to go back to file browser view |
|
139 connect(this, SIGNAL(aboutToClose()), this, SLOT(backButtonClicked())); |
|
140 } |
|
141 |
|
142 void SearchView::backButtonClicked() |
|
143 { |
|
144 mMainWindow.removeView(this); |
|
145 mForm->deleteLater(); |
|
146 mForm = 0; |
|
147 mMainWindow.addView(&mMainView); |
|
148 } |
|
149 |
|
150 void SearchView::startFileSearch() |
|
151 { |
|
152 // save form data values and set them as search attributes into FB engine. |
|
153 readFormItems(); |
|
154 mEngineWrapper.setFileSearchAttributes(mAttributes); |
|
155 |
|
156 // Create busy indicator widget with label **Searching**. Launch it to screen when |
|
157 // FB Utils engine started for file search. Hide busy indicator when search completed. |
|
158 QProgressBar *progressBar = new QProgressBar(); |
|
159 progressBar->setMaximumHeight(16); |
|
160 progressBar->setMaximumWidth(200); |
|
161 progressBar->setTextVisible(false); |
|
162 progressBar->setMaximum(0); |
|
163 progressBar->setMinimum(0); |
|
164 progressBar->setValue(1); |
|
165 |
|
166 QWidget *busyIndWidget = new QWidget(); |
|
167 busyIndWidget->setGeometry(12, 50, 120, 60); |
|
168 QVBoxLayout *vbl = new QVBoxLayout(busyIndWidget); |
|
169 QLabel *label = new QLabel("**Searching**"); |
|
170 vbl->addWidget(label); |
|
171 vbl->addWidget(progressBar); |
|
172 QHBoxLayout *hbl1 = new QHBoxLayout(); |
|
173 vbl->addLayout(hbl1); |
|
174 busyIndWidget->show(); |
|
175 qApp->processEvents(); |
|
176 bool err = mEngineWrapper.searchFiles(); |
|
177 busyIndWidget->hide(); |
|
178 |
|
179 // show results of file search: |
|
180 mResults = mEngineWrapper.getSearchResults(); |
|
181 fileSearchResults(); |
|
182 } |
|
183 |
|
184 |
|
185 void SearchView::loadAttributes() |
|
186 { |
|
187 // get settings from engine; |
|
188 mAttributes = mEngineWrapper.getFileSearchAttributes(); |
|
189 |
|
190 // set data: |
|
191 mSearchFileNameItem->setContentWidgetData("text", mPath); |
|
192 mSearchFileNameItem->setContentWidgetData("text", mAttributes.mSearchDir); |
|
193 mWildCardItem->setContentWidgetData("text",mAttributes.mWildCards); |
|
194 mHasString->setContentWidgetData("text", mAttributes.mTextInFile); |
|
195 |
|
196 mRecurse->setContentWidgetData("selected",mAttributes.mRecurse); |
|
197 |
|
198 mMinSize->setContentWidgetData("text",mAttributes.mMinSize); |
|
199 mMaxSize->setContentWidgetData("text", mAttributes.mMaxSize); |
|
200 |
|
201 mMinDate->setContentWidgetData("text", mAttributes.mMinDate); |
|
202 mMaxDate->setContentWidgetData("text", mAttributes.mMaxDate); |
|
203 } |
|
204 |
|
205 |
|
206 void SearchView::fileSearchResults() |
|
207 { |
|
208 HbDialog *dialog = new HbDialog(); |
|
209 dialog->setDismissPolicy(HbPopup::TapOutside); |
|
210 dialog->setTimeout(HbPopup::NoTimeout); |
|
211 |
|
212 // Create a list and some simple content for it |
|
213 HbListWidget *resultsList = new HbListWidget(); |
|
214 resultsList->addItem(QString("%1 entries found").arg(mResults.mNumberOfFoundFiles)); |
|
215 for (int i = 0; i < mResults.mFoundFilesList->size(); i++) { |
|
216 resultsList->addItem(QString("%1").arg(mResults.mFoundFilesList->at(i))); |
|
217 } |
|
218 dialog->setContentWidget(resultsList); |
|
219 dialog->open(); |
|
220 } |
|
221 |
|
222 /** |
|
223 * Reads form items and saves values of them into member variable mAttributes |
|
224 */ |
|
225 void SearchView::readFormItems() |
|
226 { |
|
227 mAttributes.mSearchDir = mSearchFileNameItem->contentWidgetData("text").toString(); |
|
228 mAttributes.mWildCards = mWildCardItem->contentWidgetData("text").toString(); |
|
229 mAttributes.mTextInFile = mHasString->contentWidgetData("text").toString(); |
|
230 mAttributes.mMinSize = mMinSize->contentWidgetData("text").toInt(); |
|
231 mAttributes.mMaxSize = mMaxSize->contentWidgetData("text").toInt(); |
|
232 mAttributes.mMinDate = mMinDate->contentWidgetData("text").toDate(); |
|
233 mAttributes.mMaxDate = mMaxDate->contentWidgetData("text").toDate(); |
|
234 mAttributes.mRecurse = mRecurse->contentWidgetData("selected").toBool(); |
|
235 } |