15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "searchview.h" |
18 #include "searchview.h" |
19 #include "enginewrapper.h" |
19 #include "enginewrapper.h" |
|
20 #include "notifications.h" |
20 |
21 |
21 #include <HbView> |
22 #include <HbView> |
22 #include <HbMainWindow> |
|
23 |
|
24 #include <HbDataForm> |
23 #include <HbDataForm> |
25 #include <HbDataFormModel> |
24 #include <HbDataFormModel> |
26 #include <HbDataFormModelItem> |
25 #include <HbDataFormModelItem> |
27 #include <HbAction> |
26 #include <HbAction> |
28 #include <HbPushButton> |
|
29 #include <HbListWidget> |
27 #include <HbListWidget> |
30 #include <HbListWidgetItem> |
28 #include <HbListWidgetItem> |
31 #include <HbDialog> |
29 #include <HbDialog> |
32 #include <HbMenu> |
30 #include <HbToolBar> |
|
31 #include <HbProgressDialog> |
33 |
32 |
34 #include <QtGui> |
33 #include <QtGui> |
35 #include <QDir> |
34 #include <QDir> |
36 #include <QFileInfo> |
35 #include <QFileInfo> |
37 #include <QProgressBar> |
|
38 |
|
39 |
36 |
40 const QStringList RECURSEMODES = (QStringList() << "Non-recursive" << "Recursive"); |
37 const QStringList RECURSEMODES = (QStringList() << "Non-recursive" << "Recursive"); |
41 |
38 const QString acceptActionText = "Search"; |
42 SearchView::SearchView(HbView &mainView, HbMainWindow &mainWindow, EngineWrapper &engineWrapper) |
39 const QString rejectActionText = "Cancel"; |
43 : mMainWindow(mainWindow), |
40 |
44 mMainView(mainView), |
41 |
45 mEngineWrapper(engineWrapper), |
42 SearchView::SearchView(EngineWrapper &engineWrapper) |
46 mAttributes(), |
43 : mEngineWrapper(engineWrapper), |
47 mResults(), |
44 mAttributes(), |
48 mForm(0), |
45 mResults(), |
49 mSearchFileNameItem(0), |
46 mForm(0), |
50 mWildCardItem(0), |
47 mSearchFileNameItem(0), |
51 mHasString(0), |
48 mWildCardItem(0), |
52 mRecurse(0), |
49 mHasString(0), |
53 mMinSize(0), |
50 mRecurse(0), |
54 mMaxSize(0), |
51 mMinSize(0), |
55 mMinDate(0), |
52 mMaxSize(0), |
56 mMaxDate(0), |
53 mMinDate(0), |
57 mPath() |
54 mMaxDate(0), |
58 { |
55 mPath(), |
59 } |
56 mProgressDialog(0) |
60 |
57 { |
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 |
58 // Set title and add this view to main window |
71 setTitle("Search"); |
59 setTitle("Search"); |
72 |
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 SearchView::~SearchView() |
|
71 { |
|
72 } |
|
73 |
|
74 void SearchView::initDataForm() { |
73 mForm = new HbDataForm(/*HbFormView::ModeEdit,*/ this); |
75 mForm = new HbDataForm(/*HbFormView::ModeEdit,*/ this); |
74 HbDataFormModel *model = new HbDataFormModel(); |
76 HbDataFormModel *model = new HbDataFormModel(); |
75 mPath = path; |
77 |
76 mSearchFileNameItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
78 mSearchFileNameItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
77 mSearchFileNameItem->setLabel("Search dir: "); |
79 mSearchFileNameItem->setLabel("Search dir: "); |
78 |
80 |
79 mWildCardItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
81 mWildCardItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
80 mWildCardItem->setLabel("Wildcards: "); |
82 mWildCardItem->setLabel("Wildcards: "); |
81 |
83 |
82 mHasString = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
84 mHasString = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
83 mHasString->setLabel("Has string: "); |
85 mHasString->setLabel("Has string: "); |
84 |
86 |
85 mRecurse = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem); |
87 mRecurse = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem); |
86 mRecurse->setLabel("Recurse: "); |
88 mRecurse->setLabel("Recurse: "); |
87 mRecurse->setContentWidgetData("items", RECURSEMODES); |
89 mRecurse->setContentWidgetData("items", RECURSEMODES); |
88 |
90 |
89 mMinSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
91 mMinSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
90 mMinSize->setLabel("Min size: "); |
92 mMinSize->setLabel("Min size: "); |
91 |
93 |
92 mMaxSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
94 mMaxSize = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
93 mMaxSize->setLabel("Max size: "); |
95 mMaxSize->setLabel("Max size: "); |
94 |
96 |
95 mMinDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
97 mMinDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
96 mMinDate->setLabel("Min date: "); |
98 mMinDate->setLabel("Min date: "); |
97 mMinDate->setContentWidgetData("text", "01/01/1980"); |
99 mMinDate->setContentWidgetData("text", "01/01/1980"); |
98 |
100 |
99 mMaxDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
101 mMaxDate = new HbDataFormModelItem(HbDataFormModelItem::TextItem); |
100 mMaxDate->setLabel("Max date: "); |
102 mMaxDate->setLabel("Max date: "); |
101 mMaxDate->setContentWidgetData("text", "31/12/2060"); |
103 mMaxDate->setContentWidgetData("text", "31/12/2060"); |
102 |
104 |
103 // load file search attribute values from FB engine: |
|
104 loadAttributes(); |
|
105 |
|
106 model->appendDataFormItem(mSearchFileNameItem); |
105 model->appendDataFormItem(mSearchFileNameItem); |
107 model->appendDataFormItem(mWildCardItem); |
106 model->appendDataFormItem(mWildCardItem); |
108 model->appendDataFormItem(mHasString); |
107 model->appendDataFormItem(mHasString); |
109 model->appendDataFormItem(mRecurse); |
108 model->appendDataFormItem(mRecurse); |
110 model->appendDataFormItem(mMinSize); |
109 model->appendDataFormItem(mMinSize); |
112 model->appendDataFormItem(mMinDate); |
111 model->appendDataFormItem(mMinDate); |
113 model->appendDataFormItem(mMaxDate); |
112 model->appendDataFormItem(mMaxDate); |
114 mForm->setModel(model); |
113 mForm->setModel(model); |
115 |
114 |
116 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this); |
115 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this); |
117 |
116 layout->addItem(mForm); |
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); |
117 setLayout(layout); |
138 // about to close connect to go back to file browser view |
118 } |
139 connect(this, SIGNAL(aboutToClose()), this, SLOT(backButtonClicked())); |
119 |
140 } |
120 void SearchView::createToolbar() |
141 |
121 { |
142 void SearchView::backButtonClicked() |
122 HbToolBar *toolBar = new HbToolBar(this); |
143 { |
123 HbAction *acceptAction = new HbAction(acceptActionText); |
144 mMainWindow.removeView(this); |
124 connect(acceptAction, SIGNAL(triggered()), this, SLOT(accept())); |
145 mForm->deleteLater(); |
125 toolBar->addAction(acceptAction); |
146 mForm = 0; |
126 |
147 mMainWindow.addView(&mMainView); |
127 HbAction *rejectAction = new HbAction(rejectActionText); |
148 } |
128 connect(rejectAction, SIGNAL(triggered()), this, SLOT(reject())); |
149 |
129 toolBar->addAction(rejectAction); |
150 void SearchView::startFileSearch() |
130 |
151 { |
131 setToolBar(toolBar); |
152 // save form data values and set them as search attributes into FB engine. |
132 } |
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 |
133 |
185 void SearchView::loadAttributes() |
134 void SearchView::loadAttributes() |
186 { |
135 { |
187 // get settings from engine; |
136 // get settings from engine; |
188 mAttributes = mEngineWrapper.getFileSearchAttributes(); |
137 mAttributes = mEngineWrapper.getFileSearchAttributes(); |
189 |
138 |
190 // set data: |
139 // set data: |
191 mSearchFileNameItem->setContentWidgetData("text", mPath); |
140 mSearchFileNameItem->setContentWidgetData("text", mPath); |
192 mSearchFileNameItem->setContentWidgetData("text", mAttributes.mSearchDir); |
141 // mSearchFileNameItem->setContentWidgetData("text", mAttributes.mSearchDir); |
193 mWildCardItem->setContentWidgetData("text",mAttributes.mWildCards); |
142 mWildCardItem->setContentWidgetData("text",mAttributes.mWildCards); |
194 mHasString->setContentWidgetData("text", mAttributes.mTextInFile); |
143 mHasString->setContentWidgetData("text", mAttributes.mTextInFile); |
195 |
144 |
196 mRecurse->setContentWidgetData("selected",mAttributes.mRecurse); |
145 mRecurse->setContentWidgetData("selected",mAttributes.mRecurse); |
197 |
146 |
198 mMinSize->setContentWidgetData("text",mAttributes.mMinSize); |
147 mMinSize->setContentWidgetData("text",mAttributes.mMinSize); |
199 mMaxSize->setContentWidgetData("text", mAttributes.mMaxSize); |
148 mMaxSize->setContentWidgetData("text", mAttributes.mMaxSize); |
200 |
149 |
201 mMinDate->setContentWidgetData("text", mAttributes.mMinDate); |
150 mMinDate->setContentWidgetData("text", mAttributes.mMinDate); |
202 mMaxDate->setContentWidgetData("text", mAttributes.mMaxDate); |
151 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 } |
152 } |
221 |
153 |
222 /** |
154 /** |
223 * Reads form items and saves values of them into member variable mAttributes |
155 * Reads form items and saves values of them into member variable mAttributes |
224 */ |
156 */ |