|
1 /* |
|
2 * Copyright (c) 2009 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 * |
|
15 * Description: |
|
16 * The source file of the file dialog implement |
|
17 * |
|
18 */ |
|
19 |
|
20 #include "fmfiledialog_p.h" |
|
21 #include "fmfilewidget.h" |
|
22 #include "fmcommon.h" |
|
23 |
|
24 #include "hbfontspec.h" |
|
25 #include <hbaction.h> |
|
26 #include <hbpushbutton.h> |
|
27 #include <hblabel.h> |
|
28 #include <hblineedit.h> |
|
29 #include <QGraphicsLinearLayout> |
|
30 |
|
31 #define backButtonIcon ":image/qtg_indi_status_back.svg" |
|
32 |
|
33 /*! |
|
34 constructor |
|
35 */ |
|
36 FmFileDialogPrivate::FmFileDialogPrivate( FmFileDialog *fileDialog ) : |
|
37 mFileDialog( fileDialog ), |
|
38 mHeadingWidget( 0 ), |
|
39 mCurrentPathLabel( 0 ), |
|
40 mUpButton( 0 ), |
|
41 mTitleLabel( 0 ), |
|
42 mContentWidget( 0 ), |
|
43 mContentLayout( 0 ), |
|
44 mFileWidget( 0 ), |
|
45 mOkAction( 0 ), |
|
46 mCancelAction( 0 ), |
|
47 mFileNameTitleLabel( 0 ), |
|
48 mFileNameLineEdit( 0 ) |
|
49 { |
|
50 } |
|
51 |
|
52 /*! |
|
53 destructor |
|
54 */ |
|
55 FmFileDialogPrivate::~FmFileDialogPrivate() |
|
56 { |
|
57 |
|
58 } |
|
59 |
|
60 /*! |
|
61 init |
|
62 \param directory . |
|
63 */ |
|
64 void FmFileDialogPrivate::init( const FmFileDialogArgs &args ) |
|
65 { |
|
66 mArgs = args; |
|
67 setProperties(); |
|
68 createHeadingWidget(); |
|
69 createContentWidget(); |
|
70 createBottomWidget(); |
|
71 |
|
72 if( !mFileDialog->primaryAction() && !mFileDialog->secondaryAction() ) { |
|
73 createAndSetActions(mFileDialog->tr("Ok"),mFileDialog->tr("Cancel")); |
|
74 } |
|
75 |
|
76 makeConnections(); |
|
77 setRootPath( mArgs.mDirectory ); |
|
78 mFileWidget->setModelFilter( mArgs.mDirFilters ); |
|
79 mFileWidget->setNameFilters( mArgs.mNameFilters ); |
|
80 } |
|
81 |
|
82 /*! |
|
83 createAndSetActions |
|
84 |
|
85 \param primaryActionText |
|
86 secondaryActionText |
|
87 */ |
|
88 void FmFileDialogPrivate::createAndSetActions(const QString & primaryActionText, |
|
89 const QString & secondaryActionText) |
|
90 { |
|
91 // Create action for ok button and assign it to the primary action of popup |
|
92 mOkAction = new HbAction( primaryActionText, mFileDialog ); |
|
93 mOkAction->setObjectName( "okAction" ); |
|
94 Q_ASSERT( mOkAction ); |
|
95 mFileDialog->setPrimaryAction( mOkAction ); |
|
96 |
|
97 // Create action for cancel button and assign it to the secondary action of popup |
|
98 mCancelAction = new HbAction( secondaryActionText, mFileDialog ); |
|
99 mCancelAction->setObjectName( "cancelAction" ); |
|
100 Q_ASSERT( mCancelAction ); |
|
101 mFileDialog->setSecondaryAction( mCancelAction ); |
|
102 } |
|
103 |
|
104 /*! |
|
105 setProperties |
|
106 sets the properties of the file dialog like timeout, |
|
107 Dismiss policy,modal etc. |
|
108 */ |
|
109 void FmFileDialogPrivate::setProperties() |
|
110 { |
|
111 // set the file dialog as Modal. |
|
112 mFileDialog->setModal(true); |
|
113 |
|
114 // no dismiss for File dialog. |
|
115 mFileDialog->setDismissPolicy( HbPopup::NoDismiss ); |
|
116 |
|
117 // File dialog will not time out. |
|
118 mFileDialog->setTimeout( HbPopup::NoTimeout ); |
|
119 } |
|
120 |
|
121 /*! |
|
122 makeConnections |
|
123 */ |
|
124 void FmFileDialogPrivate::makeConnections() |
|
125 { |
|
126 mFileDialog->connect( mUpButton,SIGNAL( clicked() ), |
|
127 mFileDialog, SLOT( _q_handleUpButton() ) ); |
|
128 |
|
129 if( mFileNameLineEdit ) { |
|
130 mFileDialog->connect( mFileNameLineEdit, SIGNAL( textChanged( QString ) ), |
|
131 mFileDialog, SLOT( _q_handleTextChanged( QString ) ) ); |
|
132 } |
|
133 |
|
134 mFileDialog->connect( mFileWidget, SIGNAL( pathChanged( QString ) ), |
|
135 mFileDialog, SLOT( _q_handlePathChanged( QString ) ) ); |
|
136 |
|
137 mFileDialog->connect( mFileWidget, SIGNAL( fileActivated( QString ) ), |
|
138 mFileDialog, SLOT( _q_handleFileActivated( QString ) ) ); |
|
139 } |
|
140 |
|
141 /*! |
|
142 creates the heading wiget elements that include |
|
143 a label for showing the current path and a push button for |
|
144 going to the parent directory. |
|
145 */ |
|
146 void FmFileDialogPrivate::createHeadingWidget() |
|
147 { |
|
148 mHeadingWidget = new HbWidget( mFileDialog ); |
|
149 mHeadingWidget->setObjectName( "headingWidget" ); |
|
150 |
|
151 QGraphicsLinearLayout *headingLayout = new QGraphicsLinearLayout; |
|
152 headingLayout->setOrientation(Qt::Horizontal); |
|
153 mHeadingWidget->setLayout(headingLayout); |
|
154 |
|
155 |
|
156 QGraphicsLinearLayout *titleLayout = new QGraphicsLinearLayout; |
|
157 titleLayout->setOrientation(Qt::Vertical); |
|
158 |
|
159 mTitleLabel = new HbLabel(); |
|
160 mTitleLabel->setObjectName( "titleLabel" ); |
|
161 if( mArgs.mTitle.isEmpty() ){ |
|
162 mTitleLabel->setPlainText( QString( FmPlaceholderString ) ); |
|
163 } else { |
|
164 mTitleLabel->setPlainText( mArgs.mTitle ); |
|
165 } |
|
166 |
|
167 mCurrentPathLabel = new HbLabel( QString( FmPlaceholderString ) ); |
|
168 mCurrentPathLabel->setObjectName( "currentPathLabel" ); |
|
169 mCurrentPathLabel->setElideMode(Qt::ElideRight); |
|
170 |
|
171 mUpButton = new HbPushButton; |
|
172 mUpButton->setObjectName( "upButton" ); |
|
173 mUpButton->setIcon(HbIcon(backButtonIcon)); |
|
174 |
|
175 titleLayout->addItem( mTitleLabel ); |
|
176 titleLayout->setAlignment( mTitleLabel, Qt::AlignLeft); |
|
177 |
|
178 titleLayout->addItem( mCurrentPathLabel ); |
|
179 titleLayout->setAlignment( mCurrentPathLabel, Qt::AlignLeft); |
|
180 |
|
181 headingLayout->addItem(titleLayout); |
|
182 headingLayout->addItem( mUpButton ) ; |
|
183 headingLayout->setAlignment(mUpButton,Qt::AlignRight); |
|
184 |
|
185 mFileDialog->setHeadingWidget( mHeadingWidget ); |
|
186 } |
|
187 |
|
188 /*! |
|
189 Creates the content widget. It includes the listview and model. |
|
190 |
|
191 */ |
|
192 |
|
193 void FmFileDialogPrivate::createContentWidget() |
|
194 { |
|
195 mContentWidget = new HbWidget( mFileDialog ); |
|
196 mContentWidget->setObjectName( "contentWidget" ); |
|
197 |
|
198 mContentLayout = new QGraphicsLinearLayout; |
|
199 mContentLayout->setOrientation(Qt::Vertical); |
|
200 |
|
201 mContentWidget->setLayout( mContentLayout ); |
|
202 |
|
203 mFileWidget = new FmFileWidget( mContentWidget ); |
|
204 mFileWidget->setObjectName( "fileWidget" ); |
|
205 mContentLayout->addItem( mFileWidget ); |
|
206 |
|
207 mFileDialog->setContentWidget( mContentWidget ); |
|
208 } |
|
209 |
|
210 /*! |
|
211 Creates the content widget. It includes the listview and model. |
|
212 |
|
213 */ |
|
214 |
|
215 void FmFileDialogPrivate::createBottomWidget() |
|
216 { |
|
217 if( mArgs.mDialogMode == GetDirMode ) { |
|
218 return; |
|
219 } |
|
220 HbWidget *bottomWidget = new HbWidget( mContentWidget ); |
|
221 bottomWidget->setObjectName( "bottomWidget" ); |
|
222 mContentLayout->addItem( bottomWidget ); |
|
223 |
|
224 QGraphicsLinearLayout *bottomLayout = new QGraphicsLinearLayout; |
|
225 bottomLayout->setOrientation( Qt::Horizontal ); |
|
226 |
|
227 mFileNameTitleLabel = new HbLabel( mFileDialog->tr( "file name:" ), bottomWidget ); |
|
228 mFileNameTitleLabel->setObjectName( "fileNameTitleLabel" ); |
|
229 bottomLayout->addItem( mFileNameTitleLabel ); |
|
230 |
|
231 mFileNameLineEdit = new HbLineEdit( bottomWidget ); |
|
232 mFileNameLineEdit->setObjectName( "fileNameLineEdit" ); |
|
233 bottomLayout->addItem( mFileNameLineEdit ); |
|
234 |
|
235 bottomWidget->setLayout( bottomLayout ); |
|
236 |
|
237 } |
|
238 |
|
239 void FmFileDialogPrivate::checkUpButton() |
|
240 { |
|
241 QString currentPath = mFileWidget->currentPath().absoluteFilePath(); |
|
242 bool isPreventDirUp = mArgs.mOptions & FmFileDialog::PreventDirUp; |
|
243 |
|
244 if( mFileWidget->currentViewType() == FmFileWidget::DirView ) { |
|
245 if( isPreventDirUp && |
|
246 mArgs.mDirectory.contains( currentPath, Qt::CaseInsensitive ) ) { |
|
247 // disable up when client lock top leve folder |
|
248 mUpButton->setEnabled( false ); |
|
249 } else { |
|
250 mUpButton->setEnabled( true ); |
|
251 } |
|
252 } else { |
|
253 // disable up button when at drive view |
|
254 mUpButton->setEnabled( false ); |
|
255 } |
|
256 } |
|
257 |
|
258 void FmFileDialogPrivate::checkBottomFileWidget() |
|
259 { |
|
260 switch( mArgs.mDialogMode ) |
|
261 { |
|
262 case GetDirMode: |
|
263 break; |
|
264 case GetFileMode: |
|
265 if( mFileNameLineEdit ){ |
|
266 mFileNameLineEdit->setReadOnly( true ); |
|
267 } |
|
268 break; |
|
269 case SaveFileMode: |
|
270 if( mFileNameLineEdit ){ |
|
271 if( mFileWidget->currentPath().absoluteFilePath().isEmpty() ) { |
|
272 mFileNameLineEdit->setReadOnly( true ); |
|
273 } else { |
|
274 mFileNameLineEdit->setReadOnly( false ); |
|
275 } |
|
276 } |
|
277 break; |
|
278 } |
|
279 } |
|
280 |
|
281 void FmFileDialogPrivate::checkActions() |
|
282 { |
|
283 switch( mArgs.mDialogMode ) |
|
284 { |
|
285 case GetDirMode: |
|
286 if( mFileWidget->currentPath().absoluteFilePath().isEmpty() ) { |
|
287 mOkAction->setDisabled( true ); |
|
288 } else { |
|
289 mOkAction->setDisabled( false ); |
|
290 } |
|
291 break; |
|
292 case GetFileMode: |
|
293 case SaveFileMode: |
|
294 if( mFileWidget->currentPath().absoluteFilePath().isEmpty() || |
|
295 ( mFileNameLineEdit && mFileNameLineEdit->text().isEmpty() ) ) { |
|
296 mOkAction->setDisabled( true ); |
|
297 } else { |
|
298 mOkAction->setDisabled( false ); |
|
299 } |
|
300 break; |
|
301 default: |
|
302 Q_ASSERT( false ); |
|
303 } |
|
304 } |
|
305 |
|
306 void FmFileDialogPrivate::_q_handleUpButton() |
|
307 { |
|
308 bool isPreventDirUp = mArgs.mOptions & FmFileDialog::PreventDirUp; |
|
309 QString currentPath = mFileWidget->currentPath().absoluteFilePath(); |
|
310 if( isPreventDirUp && |
|
311 mArgs.mDirectory.contains( currentPath, Qt::CaseInsensitive ) ) { |
|
312 return; |
|
313 } else { |
|
314 mFileWidget->cdUp(); |
|
315 } |
|
316 } |
|
317 |
|
318 void FmFileDialogPrivate::_q_handleTextChanged(const QString &text) |
|
319 { |
|
320 Q_UNUSED( text ); |
|
321 checkActions(); |
|
322 } |
|
323 |
|
324 void FmFileDialogPrivate::_q_handlePathChanged( const QString &path ) |
|
325 { |
|
326 if( path.isEmpty() ) { |
|
327 mCurrentPathLabel->setPlainText( QString( FmPlaceholderString ) ); |
|
328 } else { |
|
329 mCurrentPathLabel->setPlainText( path ); |
|
330 } |
|
331 |
|
332 if( mFileNameLineEdit && mArgs.mDialogMode == GetFileMode ) { |
|
333 mFileNameLineEdit->setText( QString() ); |
|
334 } |
|
335 |
|
336 checkUpButton(); |
|
337 checkBottomFileWidget(); |
|
338 checkActions(); |
|
339 } |
|
340 |
|
341 void FmFileDialogPrivate::_q_handleFileActivated( const QString &path ) |
|
342 { |
|
343 if( mFileNameLineEdit ) { |
|
344 mFileNameLineEdit->setText( path ); |
|
345 } |
|
346 checkActions(); |
|
347 } |
|
348 |
|
349 QString FmFileDialogPrivate::currentPath() const |
|
350 { |
|
351 return mFileWidget->currentPath().absoluteFilePath(); |
|
352 } |
|
353 |
|
354 QString FmFileDialogPrivate::selectedFile() const |
|
355 { |
|
356 return mFileNameLineEdit->text(); |
|
357 } |
|
358 |
|
359 void FmFileDialogPrivate::setRootPath( const QString &pathName ) |
|
360 { |
|
361 mFileWidget->setRootPath( pathName ); |
|
362 } |
|
363 |
|
364 bool FmFileDialogPrivate::isOkAction( HbAction *action ) |
|
365 { |
|
366 if( mOkAction == action ) { |
|
367 return true; |
|
368 } |
|
369 |
|
370 return false; |
|
371 } |
|
372 |
|
373 void FmFileDialogPrivate::setRetAction( HbAction *action ) |
|
374 { |
|
375 mRetAction = action; |
|
376 } |
|
377 |
|
378 HbAction *FmFileDialogPrivate::retAction() |
|
379 { |
|
380 return mRetAction; |
|
381 } |
|
382 |
|
383 QEventLoop &FmFileDialogPrivate::eventLoop() |
|
384 { |
|
385 return mEventLoop; |
|
386 } |
|
387 |
|
388 #include "moc_fmfiledialog.cpp" |