|
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 "fbfolderselectiondialog.h" |
|
19 #include "fbfolderselectorwrapper.h" |
|
20 |
|
21 #include <HbListWidget> |
|
22 #include <HbAction> |
|
23 #include <HbListWidgetItem> |
|
24 #include <HbLabel> |
|
25 #include <HbPushButton> |
|
26 |
|
27 #include <QGraphicsLinearLayout> |
|
28 #include <QFileInfo> |
|
29 #include <QFileIconProvider> |
|
30 |
|
31 /** |
|
32 * Constructor |
|
33 */ |
|
34 FbFolderSelectionDialog::FbFolderSelectionDialog(QGraphicsItem *parent) : |
|
35 HbDialog(parent), |
|
36 mTitle(0), |
|
37 mCurrentPath(0), |
|
38 mFolderList(0), |
|
39 mFolderSelectorWrapper(0), |
|
40 mFileIconProvider(0) |
|
41 { |
|
42 init(); |
|
43 } |
|
44 |
|
45 /** |
|
46 * Destructor |
|
47 */ |
|
48 FbFolderSelectionDialog::~FbFolderSelectionDialog() |
|
49 { |
|
50 if (mFileIconProvider) |
|
51 delete mFileIconProvider; |
|
52 } |
|
53 |
|
54 /** |
|
55 * Provide currenntly selected folder |
|
56 * \return current folder |
|
57 */ |
|
58 QString FbFolderSelectionDialog::selectedFolder() |
|
59 { |
|
60 return mFolderSelectorWrapper->currentPath(); |
|
61 } |
|
62 |
|
63 /** |
|
64 * Initialize folder selection dialog |
|
65 */ |
|
66 void FbFolderSelectionDialog::init() |
|
67 { |
|
68 setAttribute(Qt::WA_DeleteOnClose); |
|
69 |
|
70 mFileIconProvider = new QFileIconProvider(); |
|
71 |
|
72 createHeading(); |
|
73 createList(); |
|
74 createToolBar(); |
|
75 } |
|
76 |
|
77 /** |
|
78 * Create dialog heading widget |
|
79 */ |
|
80 void FbFolderSelectionDialog::createHeading() |
|
81 { |
|
82 HbWidget *headingWidget = new HbWidget(this); |
|
83 QGraphicsLinearLayout *headingLayout = new QGraphicsLinearLayout(Qt::Horizontal); |
|
84 headingWidget->setLayout(headingLayout); |
|
85 |
|
86 QGraphicsLinearLayout *titleLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
87 mTitle = new HbLabel(this); |
|
88 mCurrentPath = new HbLabel(this); |
|
89 mCurrentPath->setPlainText(" "); |
|
90 mCurrentPath->setElideMode(Qt::ElideMiddle); |
|
91 titleLayout->addItem(mTitle); |
|
92 titleLayout->setAlignment( mTitle, Qt::AlignLeft); |
|
93 titleLayout->addItem(mCurrentPath); |
|
94 titleLayout->setAlignment( mCurrentPath, Qt::AlignLeft); |
|
95 |
|
96 HbPushButton *moveUpButton = new HbPushButton(headingWidget); |
|
97 moveUpButton->setIcon(HbIcon(QString(":/qtg_indi_status_back.svg"))); |
|
98 connect(moveUpButton, SIGNAL(pressed()), |
|
99 this, SLOT(moveUpPressed())); |
|
100 |
|
101 headingLayout->addItem(titleLayout); |
|
102 headingLayout->addItem(moveUpButton); |
|
103 headingLayout->setAlignment(moveUpButton, Qt::AlignRight); |
|
104 |
|
105 setHeadingWidget(headingWidget); |
|
106 } |
|
107 |
|
108 /** |
|
109 * Create dialog content widget as a list of files |
|
110 */ |
|
111 void FbFolderSelectionDialog::createList() |
|
112 { |
|
113 mFolderList = new HbListWidget(this); |
|
114 mFolderSelectorWrapper = new FbFolderSelectorWrapper(); |
|
115 mFolderSelectorWrapper->init(); |
|
116 |
|
117 refreshView(); |
|
118 |
|
119 setContentWidget(mFolderList); |
|
120 connect(mFolderList, SIGNAL(activated(HbListWidgetItem *)), |
|
121 this, SLOT(activated(HbListWidgetItem *))); |
|
122 |
|
123 connect(mFolderSelectorWrapper, SIGNAL(FolderSelectionChanged()), |
|
124 this, SLOT(refreshView())); |
|
125 } |
|
126 |
|
127 /** |
|
128 * Create dialog toolbar |
|
129 */ |
|
130 void FbFolderSelectionDialog::createToolBar() |
|
131 { |
|
132 HbAction *acceptAction = new HbAction(this); |
|
133 acceptAction->setEnabled(false); |
|
134 connect(acceptAction, SIGNAL(triggered()), |
|
135 this, SLOT(acceptTriggered())); |
|
136 addAction(acceptAction); |
|
137 |
|
138 HbAction *rejectAction = new HbAction(QString("Cancel"), this); |
|
139 addAction(rejectAction); |
|
140 } |
|
141 |
|
142 /** |
|
143 * Refresh list widget content |
|
144 */ |
|
145 void FbFolderSelectionDialog::refreshView() |
|
146 { |
|
147 mFolderList->clear(); |
|
148 QIcon icon; |
|
149 mCurrentPath->setPlainText(mFolderSelectorWrapper->currentPath()); |
|
150 if (mFolderSelectorWrapper->isDriveListViewActive()) |
|
151 { |
|
152 const QString KSimpleDriveEntry("%d\t%c: <%S>\t\t"); |
|
153 //TODO icon = mFileIconProvider->icon(QFileIconProvider::Drive); |
|
154 icon = mFileIconProvider->icon(QFileIconProvider::File); |
|
155 |
|
156 for (TInt i=0; i<mFolderSelectorWrapper->itemCount(); i++) { |
|
157 FbDriveEntry driveEntry = mFolderSelectorWrapper->getDriveEntry(i); |
|
158 |
|
159 const QString SimpleDriveEntry("%1: <%2>"); |
|
160 QString diskName = SimpleDriveEntry.arg(driveEntry.driveLetter()).arg(driveEntry.mediaTypeString()); |
|
161 |
|
162 mFolderList->addItem(icon, diskName); |
|
163 } |
|
164 |
|
165 if (actions().count() > 1) { |
|
166 actions().at(0)->setEnabled(false); |
|
167 } |
|
168 } else { |
|
169 const QString SimpleFileEntry("%1"); |
|
170 icon = mFileIconProvider->icon(QFileIconProvider::Folder); |
|
171 |
|
172 for (TInt i=0; i<mFolderSelectorWrapper->itemCount(); i++) { |
|
173 FbFileEntry fileEntry = mFolderSelectorWrapper->getFileEntry(i); |
|
174 |
|
175 QString fileName = SimpleFileEntry.arg(fileEntry.name()); ///*<< fileEntry.IconId()*/ |
|
176 |
|
177 mFolderList->addItem(icon, fileName); |
|
178 } |
|
179 |
|
180 if (actions().count() > 1) { |
|
181 actions().at(0)->setEnabled(true); |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 /** |
|
187 * Slot called when list item is activated |
|
188 */ |
|
189 void FbFolderSelectionDialog::activated(HbListWidgetItem * item) |
|
190 { |
|
191 int row = mFolderList->row(item); |
|
192 if (mFolderSelectorWrapper->isDriveListViewActive()) { |
|
193 mFolderSelectorWrapper->moveDownToDirectory(row); |
|
194 } else if (row >= 0) { |
|
195 mFolderSelectorWrapper->moveDownToDirectory(row); |
|
196 } |
|
197 } |
|
198 |
|
199 /** |
|
200 * Slot handling the move up button to move up one leve in directory hierarchy |
|
201 */ |
|
202 void FbFolderSelectionDialog::moveUpPressed() |
|
203 { |
|
204 mFolderSelectorWrapper->moveUpOneLevel(); |
|
205 } |
|
206 |
|
207 void FbFolderSelectionDialog::acceptTriggered() |
|
208 { |
|
209 accept(); |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 |
|
214 /** |
|
215 * Constructor |
|
216 */ |
|
217 FbCopyToFolderSelectionDialog::FbCopyToFolderSelectionDialog(QGraphicsItem *parent) : |
|
218 FbFolderSelectionDialog(parent) |
|
219 { |
|
220 if (headingWidget()) { |
|
221 mTitle->setPlainText(QString("Copy to")); |
|
222 } |
|
223 if (actions().count() > 1) { |
|
224 actions().at(0)->setText(QString("Copy here")); |
|
225 } |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 |
|
230 /** |
|
231 * Constructor |
|
232 */ |
|
233 FbMoveToFolderSelectionDialog::FbMoveToFolderSelectionDialog(QGraphicsItem *parent) : |
|
234 FbFolderSelectionDialog(parent) |
|
235 { |
|
236 if (headingWidget()) { |
|
237 mTitle->setPlainText(QString("Move to")); |
|
238 } |
|
239 if (actions().count() > 1) { |
|
240 actions().at(0)->setText(QString("Move here")); |
|
241 } |
|
242 } |
|
243 |
|
244 // End of file |