1 | //Added by qt3to4:
|
---|
2 | #include <Q3WhatsThis>
|
---|
3 | #include <QPushButton>
|
---|
4 | #include <Q3HBoxLayout>
|
---|
5 | #include <Q3ValueList>
|
---|
6 | #include <QLabel>
|
---|
7 | #include <Q3GridLayout>
|
---|
8 | #include <QMouseEvent>
|
---|
9 | #include <QEvent>
|
---|
10 | #include <Q3VBoxLayout>
|
---|
11 | #include <QShowEvent>
|
---|
12 | /**
|
---|
13 | *
|
---|
14 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
15 | * "Shared Folders" settings dialog UI include (Qt Designer)
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*
|
---|
19 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
20 | *
|
---|
21 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
22 | * available from http://www.virtualbox.org. This file is free software;
|
---|
23 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
24 | * General Public License (GPL) as published by the Free Software
|
---|
25 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
26 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
27 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /****************************************************************************
|
---|
31 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
32 | **
|
---|
33 | ** If you want to add, delete, or rename functions or slots, use
|
---|
34 | ** Qt Designer to update this file, preserving your code.
|
---|
35 | **
|
---|
36 | ** You should not define a constructor or destructor in this file.
|
---|
37 | ** Instead, write your code in functions called init() and destroy().
|
---|
38 | ** These will automatically be called by the form's constructor and
|
---|
39 | ** destructor.
|
---|
40 | *****************************************************************************/
|
---|
41 |
|
---|
42 |
|
---|
43 | typedef QPair<QString, VBoxSharedFoldersSettings::SFDialogType> SFolderName;
|
---|
44 | typedef Q3ValueList<SFolderName> SFoldersNameList;
|
---|
45 |
|
---|
46 |
|
---|
47 | class VBoxRichListItem : public Q3ListViewItem
|
---|
48 | {
|
---|
49 | public:
|
---|
50 |
|
---|
51 | enum { QIRichListItemId = 1010 };
|
---|
52 |
|
---|
53 | enum FormatType
|
---|
54 | {
|
---|
55 | IncorrectFormat = 0,
|
---|
56 | EllipsisStart = 1,
|
---|
57 | EllipsisMiddle = 2,
|
---|
58 | EllipsisEnd = 3,
|
---|
59 | EllipsisFile = 4
|
---|
60 | };
|
---|
61 |
|
---|
62 | VBoxRichListItem (FormatType aFormat, Q3ListView *aParent,
|
---|
63 | const QString& aName, const QString& aNull1,
|
---|
64 | const QString& aNull2, const QString& aKey) :
|
---|
65 | Q3ListViewItem (aParent, aName, aNull1, aNull2, aKey), mFormat (aFormat)
|
---|
66 | {
|
---|
67 | }
|
---|
68 |
|
---|
69 | VBoxRichListItem (FormatType aFormat, Q3ListViewItem *aParent,
|
---|
70 | const QString& aName, const QString& aPath,
|
---|
71 | const QString& aAccess, const QString& aEdited) :
|
---|
72 | Q3ListViewItem (aParent, aName, aPath, aAccess, aEdited), mFormat (aFormat)
|
---|
73 | {
|
---|
74 | mTextList << aName << aPath << aAccess << aEdited;
|
---|
75 | }
|
---|
76 |
|
---|
77 | int rtti() const { return QIRichListItemId; }
|
---|
78 |
|
---|
79 | int compare (Q3ListViewItem *aItem, int aColumn, bool aAscending) const
|
---|
80 | {
|
---|
81 | /* Sorting the children always by name: */
|
---|
82 | if (parent() && aItem->parent())
|
---|
83 | return Q3ListViewItem::compare (aItem, 0, aAscending);
|
---|
84 | /* Sorting the root items always by key: */
|
---|
85 | else if (!parent() && !aItem->parent())
|
---|
86 | return Q3ListViewItem::compare (aItem, 3, aAscending);
|
---|
87 | else
|
---|
88 | return Q3ListViewItem::compare (aItem, aColumn, aAscending);
|
---|
89 | }
|
---|
90 |
|
---|
91 | VBoxRichListItem* nextSibling() const
|
---|
92 | {
|
---|
93 | Q3ListViewItem *item = Q3ListViewItem::nextSibling();
|
---|
94 | return item && item->rtti() == QIRichListItemId ?
|
---|
95 | static_cast<VBoxRichListItem*> (item) : 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | QString getText (int aIndex) const
|
---|
99 | {
|
---|
100 | return aIndex >= 0 && aIndex < (int)mTextList.size() ?
|
---|
101 | mTextList [aIndex] : QString::null;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void updateText (int aColumn, const QString &aText)
|
---|
105 | {
|
---|
106 | if (aColumn >= 0 && aColumn < (int)mTextList.size())
|
---|
107 | mTextList [aColumn] = aText;
|
---|
108 | }
|
---|
109 |
|
---|
110 | protected:
|
---|
111 |
|
---|
112 | void paintCell (QPainter *aPainter, const QColorGroup &aColorGroup,
|
---|
113 | int aColumn, int aWidth, int aAlign)
|
---|
114 | {
|
---|
115 | if (!parent())
|
---|
116 | {
|
---|
117 | /* Make root items occupy the whole width */
|
---|
118 | aWidth = listView()->viewport()->width();
|
---|
119 |
|
---|
120 | if (aColumn > 0)
|
---|
121 | {
|
---|
122 | /* For columns other than the first one, paint the overlapping
|
---|
123 | * portion of the first column after correcting the window */
|
---|
124 | aPainter->save();
|
---|
125 | QRect wnd = aPainter->window();
|
---|
126 | int dx = -listView()->treeStepSize();
|
---|
127 | for (int i = 0; i < aColumn; ++ i)
|
---|
128 | dx += listView()->columnWidth (i);
|
---|
129 | wnd.moveBy (dx, 0);
|
---|
130 | aPainter->setWindow (wnd);
|
---|
131 | Q3ListViewItem::paintCell (aPainter, aColorGroup, 0, aWidth, aAlign);
|
---|
132 | aPainter->restore();
|
---|
133 | return;
|
---|
134 | }
|
---|
135 |
|
---|
136 | Q3ListViewItem::paintCell (aPainter, aColorGroup, aColumn, aWidth, aAlign);
|
---|
137 | }
|
---|
138 | else
|
---|
139 | {
|
---|
140 | processColumn (aColumn, aWidth);
|
---|
141 | Q3ListViewItem::paintCell (aPainter, aColorGroup, aColumn, aWidth, aAlign);
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | int width (const QFontMetrics &aFontMetrics, const Q3ListView *, int aColumn) const
|
---|
146 | {
|
---|
147 | return parent() ?
|
---|
148 | aFontMetrics.boundingRect (getText (aColumn)).width() +
|
---|
149 | aFontMetrics.width ("...x") /* indent size */ : 0;
|
---|
150 | }
|
---|
151 |
|
---|
152 | void processColumn (int aColumn, int aWidth)
|
---|
153 | {
|
---|
154 | QString oneString = aColumn >= 0 && aColumn < (int)mTextList.size() ?
|
---|
155 | mTextList [aColumn] : QString::null;
|
---|
156 | if (oneString.isNull())
|
---|
157 | return;
|
---|
158 | int oldSize = listView()->fontMetrics().width (oneString);
|
---|
159 | int indentSize = listView()->fontMetrics().width ("...x");
|
---|
160 |
|
---|
161 | /* compress text */
|
---|
162 | int start = 0;
|
---|
163 | int finish = 0;
|
---|
164 | int position = 0;
|
---|
165 | int textWidth = 0;
|
---|
166 | do {
|
---|
167 | textWidth = listView()->fontMetrics().width (oneString);
|
---|
168 | if (textWidth + indentSize > aWidth)
|
---|
169 | {
|
---|
170 | start = 0;
|
---|
171 | finish = oneString.length();
|
---|
172 |
|
---|
173 | /* selecting remove position */
|
---|
174 | switch (mFormat)
|
---|
175 | {
|
---|
176 | case EllipsisStart:
|
---|
177 | position = start;
|
---|
178 | break;
|
---|
179 | case EllipsisMiddle:
|
---|
180 | position = (finish - start) / 2;
|
---|
181 | break;
|
---|
182 | case EllipsisEnd:
|
---|
183 | position = finish - 1;
|
---|
184 | break;
|
---|
185 | case EllipsisFile:
|
---|
186 | {
|
---|
187 | QRegExp regExp ("([\\\\/][^\\\\^/]+[\\\\/]?$)");
|
---|
188 | int newFinish = regExp.search (oneString);
|
---|
189 | if (newFinish != -1)
|
---|
190 | finish = newFinish;
|
---|
191 | position = (finish - start) / 2;
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | default:
|
---|
195 | AssertMsgFailed (("Invalid format type\n"));
|
---|
196 | }
|
---|
197 |
|
---|
198 | if (position == finish)
|
---|
199 | break;
|
---|
200 | oneString.remove (position, 1);
|
---|
201 | }
|
---|
202 | } while (textWidth + indentSize > aWidth);
|
---|
203 | if (position || mFormat == EllipsisFile) oneString.insert (position, "...");
|
---|
204 |
|
---|
205 | int newSize = listView()->fontMetrics().width (oneString);
|
---|
206 | setText (aColumn, newSize < oldSize ? oneString : mTextList [aColumn]);
|
---|
207 | }
|
---|
208 |
|
---|
209 | FormatType mFormat;
|
---|
210 | QStringList mTextList;
|
---|
211 | };
|
---|
212 |
|
---|
213 |
|
---|
214 | class VBoxAddSFDialog : public QDialog
|
---|
215 | {
|
---|
216 | Q_OBJECT
|
---|
217 |
|
---|
218 | public:
|
---|
219 |
|
---|
220 | enum DialogType { AddDialogType, EditDialogType };
|
---|
221 |
|
---|
222 | VBoxAddSFDialog (VBoxSharedFoldersSettings *aParent,
|
---|
223 | VBoxAddSFDialog::DialogType aType,
|
---|
224 | bool aEnableSelector /* for "permanent" checkbox */,
|
---|
225 | const SFoldersNameList &aUsedNames)
|
---|
226 | : QDialog (aParent, "VBoxAddSFDialog", true /* modal */)
|
---|
227 | , mLePath (0), mLeName (0), mCbPermanent (0), mCbReadonly (0)
|
---|
228 | , mUsedNames (aUsedNames)
|
---|
229 | {
|
---|
230 | switch (aType)
|
---|
231 | {
|
---|
232 | case AddDialogType:
|
---|
233 | setCaption (tr ("Add Share"));
|
---|
234 | break;
|
---|
235 | case EditDialogType:
|
---|
236 | setCaption (tr ("Edit Share"));
|
---|
237 | break;
|
---|
238 | default:
|
---|
239 | AssertMsgFailed (("Incorrect SF Dialog type\n"));
|
---|
240 | }
|
---|
241 | Q3VBoxLayout *mainLayout = new Q3VBoxLayout (this, 10, 10, "mainLayout");
|
---|
242 |
|
---|
243 | /* Setup Input layout */
|
---|
244 | Q3GridLayout *inputLayout = new Q3GridLayout (mainLayout, 3, 3, 10, "inputLayout");
|
---|
245 | QLabel *lbPath = new QLabel (tr ("Folder Path"), this);
|
---|
246 | mLePath = new QLineEdit (this);
|
---|
247 | QToolButton *tbPath = new QToolButton (this);
|
---|
248 | QLabel *lbName = new QLabel (tr ("Folder Name"), this);
|
---|
249 | mLeName = new QLineEdit (this);
|
---|
250 | tbPath->setIconSet (VBoxGlobal::iconSet (":/select_file_16px.png",
|
---|
251 | ":/select_file_dis_16px.png"));
|
---|
252 | tbPath->setFocusPolicy (Qt::TabFocus);
|
---|
253 | connect (mLePath, SIGNAL (textChanged (const QString &)),
|
---|
254 | this, SLOT (validate()));
|
---|
255 | connect (mLeName, SIGNAL (textChanged (const QString &)),
|
---|
256 | this, SLOT (validate()));
|
---|
257 | connect (tbPath, SIGNAL (clicked()), this, SLOT (showFileDialog()));
|
---|
258 | Q3WhatsThis::add (mLePath, tr ("Displays the path to an existing folder on the host PC."));
|
---|
259 | Q3WhatsThis::add (mLeName, tr ("Displays the name of the shared folder "
|
---|
260 | "(as it will be seen by the guest OS)."));
|
---|
261 | Q3WhatsThis::add (tbPath, tr ("Opens the dialog to select a folder."));
|
---|
262 |
|
---|
263 | inputLayout->addWidget (lbPath, 0, 0);
|
---|
264 | inputLayout->addWidget (mLePath, 0, 1);
|
---|
265 | inputLayout->addWidget (tbPath, 0, 2);
|
---|
266 | inputLayout->addWidget (lbName, 1, 0);
|
---|
267 | inputLayout->addMultiCellWidget (mLeName, 1, 1, 1, 2);
|
---|
268 |
|
---|
269 | mCbReadonly = new QCheckBox (tr ("&Read-only"), this);
|
---|
270 | Q3WhatsThis::add (mCbReadonly,
|
---|
271 | tr ("When checked, the guest OS will not be able to write to the "
|
---|
272 | "specified shared folder."));
|
---|
273 | mCbReadonly->setChecked (false);
|
---|
274 | inputLayout->addMultiCellWidget (mCbReadonly, 2, 2, 0, 2);
|
---|
275 |
|
---|
276 | if (aEnableSelector)
|
---|
277 | {
|
---|
278 | mCbPermanent = new QCheckBox (tr ("&Make Permanent"), this);
|
---|
279 | mCbPermanent->setChecked (true);
|
---|
280 | inputLayout->addMultiCellWidget (mCbPermanent, 3, 3, 0, 2);
|
---|
281 | connect (mCbPermanent, SIGNAL (toggled (bool)),
|
---|
282 | this, SLOT (validate()));
|
---|
283 | }
|
---|
284 |
|
---|
285 | /* Setup Button layout */
|
---|
286 | Q3HBoxLayout *buttonLayout = new Q3HBoxLayout (mainLayout, 10, "buttonLayout");
|
---|
287 | mBtOk = new QPushButton (tr ("&OK"), this, "btOk");
|
---|
288 | QSpacerItem *spacer = new QSpacerItem (0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
---|
289 | QPushButton *btCancel = new QPushButton (tr ("Cancel"), this, "btCancel");
|
---|
290 | connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
|
---|
291 | connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
|
---|
292 |
|
---|
293 | buttonLayout->addWidget (mBtOk);
|
---|
294 | buttonLayout->addItem (spacer);
|
---|
295 | buttonLayout->addWidget (btCancel);
|
---|
296 |
|
---|
297 | /* Validate fields */
|
---|
298 | validate();
|
---|
299 | }
|
---|
300 |
|
---|
301 | ~VBoxAddSFDialog() {}
|
---|
302 |
|
---|
303 | QString getPath() { return mLePath->text(); }
|
---|
304 | QString getName() { return mLeName->text(); }
|
---|
305 | bool getPermanent()
|
---|
306 | {
|
---|
307 | return mCbPermanent ? mCbPermanent->isChecked() : true;
|
---|
308 | }
|
---|
309 | bool getWritable() { return !mCbReadonly->isChecked(); }
|
---|
310 |
|
---|
311 | void setPath (const QString &aPath) { mLePath->setText (aPath); }
|
---|
312 | void setName (const QString &aName) { mLeName->setText (aName); }
|
---|
313 | void setPermanent (bool aPermanent)
|
---|
314 | {
|
---|
315 | if (mCbPermanent)
|
---|
316 | {
|
---|
317 | mCbPermanent->setChecked (aPermanent);
|
---|
318 | mCbPermanent->setEnabled (!aPermanent);
|
---|
319 | }
|
---|
320 | }
|
---|
321 | void setWritable (bool aWritable) { mCbReadonly->setChecked (!aWritable); }
|
---|
322 |
|
---|
323 | private slots:
|
---|
324 |
|
---|
325 | void validate()
|
---|
326 | {
|
---|
327 | VBoxSharedFoldersSettings::SFDialogType dlgType =
|
---|
328 | (VBoxSharedFoldersSettings::SFDialogType)
|
---|
329 | static_cast<VBoxSharedFoldersSettings*> (parent())->dialogType();
|
---|
330 | VBoxSharedFoldersSettings::SFDialogType resultType =
|
---|
331 | mCbPermanent && !mCbPermanent->isChecked() ?
|
---|
332 | VBoxSharedFoldersSettings::ConsoleType :
|
---|
333 | dlgType & VBoxSharedFoldersSettings::MachineType ?
|
---|
334 | VBoxSharedFoldersSettings::MachineType :
|
---|
335 | VBoxSharedFoldersSettings::GlobalType;
|
---|
336 | SFolderName pair = qMakePair (mLeName->text(), resultType);
|
---|
337 |
|
---|
338 | mBtOk->setEnabled (!mLePath->text().isEmpty() &&
|
---|
339 | !mLeName->text().isEmpty() &&
|
---|
340 | !mUsedNames.contains (pair));
|
---|
341 | }
|
---|
342 |
|
---|
343 | void showFileDialog()
|
---|
344 | {
|
---|
345 | QString folder = vboxGlobal()
|
---|
346 | .getExistingDirectory (QDir::rootDirPath(),
|
---|
347 | this, "addSharedFolderDialog",
|
---|
348 | tr ("Select a folder to share"));
|
---|
349 | if (folder.isNull())
|
---|
350 | return;
|
---|
351 |
|
---|
352 | QString folderName = QDir::convertSeparators (folder);
|
---|
353 | QRegExp commonRule ("[\\\\/]([^\\\\^/]+)[\\\\/]?$");
|
---|
354 | QRegExp rootRule ("(([a-zA-Z])[^\\\\^/])?[\\\\/]$");
|
---|
355 | if (commonRule.search (folderName) != -1)
|
---|
356 | {
|
---|
357 | /* processing non-root folder */
|
---|
358 | mLePath->setText (folderName.remove (QRegExp ("[\\\\/]$")));
|
---|
359 | mLeName->setText (commonRule.cap (1));
|
---|
360 | }
|
---|
361 | else if (rootRule.search (folderName) != -1)
|
---|
362 | {
|
---|
363 | /* processing root folder */
|
---|
364 | mLePath->setText (folderName);
|
---|
365 | #if defined (Q_OS_WIN) || defined (Q_OS_OS2)
|
---|
366 | mLeName->setText (rootRule.cap (2) + "_DRIVE");
|
---|
367 | #elif defined (Q_OS_UNIX)
|
---|
368 | mLeName->setText ("ROOT");
|
---|
369 | #endif
|
---|
370 | }
|
---|
371 | else
|
---|
372 | return; /* hm, what type of folder it was? */
|
---|
373 | }
|
---|
374 |
|
---|
375 | private:
|
---|
376 |
|
---|
377 | void showEvent (QShowEvent *aEvent)
|
---|
378 | {
|
---|
379 | setFixedHeight (height());
|
---|
380 | QDialog::showEvent (aEvent);
|
---|
381 | }
|
---|
382 |
|
---|
383 | QPushButton *mBtOk;
|
---|
384 | QLineEdit *mLePath;
|
---|
385 | QLineEdit *mLeName;
|
---|
386 | QCheckBox *mCbPermanent;
|
---|
387 | QCheckBox *mCbReadonly;
|
---|
388 | SFoldersNameList mUsedNames;
|
---|
389 | };
|
---|
390 |
|
---|
391 |
|
---|
392 | void VBoxSharedFoldersSettings::init()
|
---|
393 | {
|
---|
394 | mDialogType = WrongType;
|
---|
395 | listView->setSorting (0);
|
---|
396 | new QIListViewSelectionPreserver (this, listView);
|
---|
397 | listView->setShowToolTips (false);
|
---|
398 | listView->setRootIsDecorated (true);
|
---|
399 | listView->header()->setMovingEnabled (false);
|
---|
400 | tbAdd->setIconSet (VBoxGlobal::iconSet (":/add_shared_folder_16px.png",
|
---|
401 | ":/add_shared_folder_disabled_16px.png"));
|
---|
402 | tbEdit->setIconSet (VBoxGlobal::iconSet (":/edit_shared_folder_16px.png",
|
---|
403 | ":/edit_shared_folder_disabled_16px.png"));
|
---|
404 | tbRemove->setIconSet (VBoxGlobal::iconSet (":/revome_shared_folder_16px.png",
|
---|
405 | ":/revome_shared_folder_disabled_16px.png"));
|
---|
406 | connect (tbAdd, SIGNAL (clicked()), this, SLOT (tbAddPressed()));
|
---|
407 | connect (tbEdit, SIGNAL (clicked()), this, SLOT (tbEditPressed()));
|
---|
408 | connect (tbRemove, SIGNAL (clicked()), this, SLOT (tbRemovePressed()));
|
---|
409 | connect (listView, SIGNAL (currentChanged (Q3ListViewItem *)),
|
---|
410 | this, SLOT (processCurrentChanged (Q3ListViewItem *)));
|
---|
411 |
|
---|
412 | /* Make after-paining list update to ensure all columns repainted correctly. */
|
---|
413 | connect (listView->header(), SIGNAL (sizeChange (int, int, int)),
|
---|
414 | this, SLOT (updateList()));
|
---|
415 |
|
---|
416 | mIsListViewChanged = false;
|
---|
417 |
|
---|
418 | listView->viewport()->installEventFilter (this);
|
---|
419 |
|
---|
420 | mTrFull = tr ("Full");
|
---|
421 | mTrReadOnly = tr ("Read-only");
|
---|
422 | }
|
---|
423 |
|
---|
424 | void VBoxSharedFoldersSettings::showEvent (QShowEvent *aEvent)
|
---|
425 | {
|
---|
426 | QWidget::showEvent (aEvent);
|
---|
427 |
|
---|
428 | /* Adjusting size after all pending show events are processed. */
|
---|
429 | QTimer::singleShot (0, this, SLOT (adjustList()));
|
---|
430 | }
|
---|
431 |
|
---|
432 |
|
---|
433 | void VBoxSharedFoldersSettings::updateList()
|
---|
434 | {
|
---|
435 | /* Updating list after all pending cell-repaint enevts. */
|
---|
436 | QTimer::singleShot (0, listView, SLOT (updateContents()));
|
---|
437 | }
|
---|
438 |
|
---|
439 | void VBoxSharedFoldersSettings::adjustList()
|
---|
440 | {
|
---|
441 | /* Adjust two columns size.
|
---|
442 | * Watching columns 0&2 to feat 1/3 of total width. */
|
---|
443 | int total = listView->viewport()->width();
|
---|
444 |
|
---|
445 | listView->adjustColumn (0);
|
---|
446 | int w0 = listView->columnWidth (0) < total / 3 ?
|
---|
447 | listView->columnWidth (0) : total / 3;
|
---|
448 |
|
---|
449 | listView->adjustColumn (2);
|
---|
450 | int w2 = listView->columnWidth (2) < total / 3 ?
|
---|
451 | listView->columnWidth (2) : total / 3;
|
---|
452 |
|
---|
453 | /* We are adjusting columns 0 and 2 and resizing column 1 to feat
|
---|
454 | * visible listView' width according two adjusted columns. Due to
|
---|
455 | * adjusting column 2 influent column 0 restoring all widths. */
|
---|
456 | listView->setColumnWidth (0, w0);
|
---|
457 | listView->setColumnWidth (1, total - w0 - w2);
|
---|
458 | listView->setColumnWidth (2, w2);
|
---|
459 | }
|
---|
460 |
|
---|
461 | bool VBoxSharedFoldersSettings::eventFilter (QObject *aObject, QEvent *aEvent)
|
---|
462 | {
|
---|
463 | /* Process & show auto Tool-Tip for partially hidden listview items. */
|
---|
464 | if (aObject == listView->viewport() && aEvent->type() == QEvent::MouseMove)
|
---|
465 | {
|
---|
466 | QMouseEvent *e = static_cast<QMouseEvent*> (aEvent);
|
---|
467 | Q3ListViewItem *i = listView->itemAt (e->pos());
|
---|
468 | VBoxRichListItem *item = i && i->rtti() == VBoxRichListItem::QIRichListItemId ?
|
---|
469 | static_cast<VBoxRichListItem*> (i) : 0;
|
---|
470 | if (item)
|
---|
471 | {
|
---|
472 | int delta = e->pos().x();
|
---|
473 | int id = 0;
|
---|
474 | for (; id < listView->columns(); ++ id)
|
---|
475 | {
|
---|
476 | if (delta < listView->columnWidth (id))
|
---|
477 | break;
|
---|
478 | delta -= listView->columnWidth (id);
|
---|
479 | }
|
---|
480 |
|
---|
481 | #warning port me
|
---|
482 | // QString curText = QToolTip::textFor (listView->viewport());
|
---|
483 | QString curText = "";
|
---|
484 | QString newText = item->text (id) != item->getText (id) ?
|
---|
485 | item->getText (id) : QString::null;
|
---|
486 |
|
---|
487 | if (newText != curText)
|
---|
488 | {
|
---|
489 | QToolTip::remove (listView->viewport());
|
---|
490 | QToolTip::add (listView->viewport(), newText);
|
---|
491 | }
|
---|
492 | }
|
---|
493 | else
|
---|
494 | QToolTip::remove (listView->viewport());
|
---|
495 | }
|
---|
496 |
|
---|
497 | return QWidget::eventFilter (aObject, aEvent);
|
---|
498 | }
|
---|
499 |
|
---|
500 | void VBoxSharedFoldersSettings::setDialogType (int aType)
|
---|
501 | {
|
---|
502 | mDialogType = aType;
|
---|
503 | }
|
---|
504 |
|
---|
505 |
|
---|
506 | void VBoxSharedFoldersSettings::removeSharedFolder (const QString & aName,
|
---|
507 | const QString & aPath,
|
---|
508 | SFDialogType aType)
|
---|
509 | {
|
---|
510 | switch (aType)
|
---|
511 | {
|
---|
512 | case GlobalType:
|
---|
513 | {
|
---|
514 | /* This feature is not implemented yet */
|
---|
515 | AssertMsgFailed (("Global shared folders are not implemented yet\n"));
|
---|
516 | break;
|
---|
517 | }
|
---|
518 | case MachineType:
|
---|
519 | {
|
---|
520 | Assert (!mMachine.isNull());
|
---|
521 | mMachine.RemoveSharedFolder (aName);
|
---|
522 | if (!mMachine.isOk())
|
---|
523 | vboxProblem().cannotRemoveSharedFolder (this, mMachine,
|
---|
524 | aName, aPath);
|
---|
525 | break;
|
---|
526 | }
|
---|
527 | case ConsoleType:
|
---|
528 | {
|
---|
529 | Assert (!mConsole.isNull());
|
---|
530 | mConsole.RemoveSharedFolder (aName);
|
---|
531 | if (!mConsole.isOk())
|
---|
532 | vboxProblem().cannotRemoveSharedFolder (this, mConsole,
|
---|
533 | aName, aPath);
|
---|
534 | break;
|
---|
535 | }
|
---|
536 | default:
|
---|
537 | {
|
---|
538 | AssertMsgFailed (("Incorrect shared folder type\n"));
|
---|
539 | }
|
---|
540 | }
|
---|
541 | }
|
---|
542 |
|
---|
543 | void VBoxSharedFoldersSettings::createSharedFolder (const QString & aName,
|
---|
544 | const QString & aPath,
|
---|
545 | bool aWritable,
|
---|
546 | SFDialogType aType)
|
---|
547 | {
|
---|
548 | switch (aType)
|
---|
549 | {
|
---|
550 | case GlobalType:
|
---|
551 | {
|
---|
552 | /* This feature is not implemented yet */
|
---|
553 | AssertMsgFailed (("Global shared folders are not implemented yet\n"));
|
---|
554 | break;
|
---|
555 | }
|
---|
556 | case MachineType:
|
---|
557 | {
|
---|
558 | Assert (!mMachine.isNull());
|
---|
559 | mMachine.CreateSharedFolder (aName, aPath, aWritable);
|
---|
560 | if (!mMachine.isOk())
|
---|
561 | vboxProblem().cannotCreateSharedFolder (this, mMachine,
|
---|
562 | aName, aPath);
|
---|
563 | break;
|
---|
564 | }
|
---|
565 | case ConsoleType:
|
---|
566 | {
|
---|
567 | Assert (!mConsole.isNull());
|
---|
568 | mConsole.CreateSharedFolder (aName, aPath, aWritable);
|
---|
569 | if (!mConsole.isOk())
|
---|
570 | vboxProblem().cannotCreateSharedFolder (this, mConsole,
|
---|
571 | aName, aPath);
|
---|
572 | break;
|
---|
573 | }
|
---|
574 | default:
|
---|
575 | {
|
---|
576 | AssertMsgFailed (("Incorrect shared folder type\n"));
|
---|
577 | }
|
---|
578 | }
|
---|
579 | }
|
---|
580 |
|
---|
581 |
|
---|
582 | void VBoxSharedFoldersSettings::getFromGlobal()
|
---|
583 | {
|
---|
584 | /* This feature is not implemented yet */
|
---|
585 | AssertMsgFailed (("Global shared folders are not implemented yet\n"));
|
---|
586 |
|
---|
587 | /*
|
---|
588 | QString name = tr (" Global Folders");
|
---|
589 | QString key (QString::number (GlobalType));
|
---|
590 | VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
|
---|
591 | listView, name, QString::null, QString::null, key);
|
---|
592 | getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate(), root);
|
---|
593 | */
|
---|
594 | }
|
---|
595 |
|
---|
596 | void VBoxSharedFoldersSettings::getFromMachine (const CMachine &aMachine)
|
---|
597 | {
|
---|
598 | mMachine = aMachine;
|
---|
599 | QString name = tr (" Machine Folders");
|
---|
600 | QString key (QString::number (MachineType));
|
---|
601 | VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
|
---|
602 | listView, name, QString::null, QString::null, key);
|
---|
603 | getFrom (mMachine.GetSharedFolders().Enumerate(), root);
|
---|
604 | }
|
---|
605 |
|
---|
606 | void VBoxSharedFoldersSettings::getFromConsole (const CConsole &aConsole)
|
---|
607 | {
|
---|
608 | mConsole = aConsole;
|
---|
609 | QString name = tr (" Transient Folders");
|
---|
610 | QString key (QString::number (ConsoleType));
|
---|
611 | VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
|
---|
612 | listView, name, QString::null, QString::null, key);
|
---|
613 | getFrom (mConsole.GetSharedFolders().Enumerate(), root);
|
---|
614 | }
|
---|
615 |
|
---|
616 | void VBoxSharedFoldersSettings::getFrom (const CSharedFolderEnumerator &aEn,
|
---|
617 | Q3ListViewItem *aRoot)
|
---|
618 | {
|
---|
619 | aRoot->setSelectable (false);
|
---|
620 | while (aEn.HasMore())
|
---|
621 | {
|
---|
622 | CSharedFolder sf = aEn.GetNext();
|
---|
623 | new VBoxRichListItem (VBoxRichListItem::EllipsisFile, aRoot,
|
---|
624 | sf.GetName(), sf.GetHostPath(),
|
---|
625 | sf.GetWritable() ? mTrFull : mTrReadOnly,
|
---|
626 | "not edited");
|
---|
627 | }
|
---|
628 | listView->setOpen (aRoot, true);
|
---|
629 | listView->setCurrentItem (aRoot->firstChild() ? aRoot->firstChild() : aRoot);
|
---|
630 | processCurrentChanged (aRoot->firstChild() ? aRoot->firstChild() : aRoot);
|
---|
631 | }
|
---|
632 |
|
---|
633 |
|
---|
634 | void VBoxSharedFoldersSettings::putBackToGlobal()
|
---|
635 | {
|
---|
636 | /* This feature is not implemented yet */
|
---|
637 | AssertMsgFailed (("Global shared folders are not implemented yet\n"));
|
---|
638 |
|
---|
639 | /*
|
---|
640 | if (!mIsListViewChanged) return;
|
---|
641 | // This function is only available for GlobalType dialog
|
---|
642 | Assert (mDialogType == GlobalType);
|
---|
643 | // Searching for GlobalType item's root
|
---|
644 | QListViewItem *root = listView->findItem (QString::number (GlobalType), 3);
|
---|
645 | Assert (root);
|
---|
646 | CSharedFolderEnumerator en = vboxGlobal().virtualBox().GetSharedFolders().Enumerate();
|
---|
647 | putBackTo (en, root);
|
---|
648 | */
|
---|
649 | }
|
---|
650 |
|
---|
651 | void VBoxSharedFoldersSettings::putBackToMachine()
|
---|
652 | {
|
---|
653 | if (!mIsListViewChanged)
|
---|
654 | return;
|
---|
655 |
|
---|
656 | /* This function is only available for MachineType dialog */
|
---|
657 | Assert (mDialogType & MachineType);
|
---|
658 | /* Searching for MachineType item's root */
|
---|
659 | Q3ListViewItem *root = listView->findItem (QString::number (MachineType), 3);
|
---|
660 | Assert (root);
|
---|
661 | CSharedFolderEnumerator en = mMachine.GetSharedFolders().Enumerate();
|
---|
662 | putBackTo (en, root);
|
---|
663 | }
|
---|
664 |
|
---|
665 | void VBoxSharedFoldersSettings::putBackToConsole()
|
---|
666 | {
|
---|
667 | if (!mIsListViewChanged)
|
---|
668 | return;
|
---|
669 |
|
---|
670 | /* This function is only available for ConsoleType dialog */
|
---|
671 | Assert (mDialogType & ConsoleType);
|
---|
672 | /* Searching for ConsoleType item's root */
|
---|
673 | Q3ListViewItem *root = listView->findItem (QString::number (ConsoleType), 3);
|
---|
674 | Assert (root);
|
---|
675 | CSharedFolderEnumerator en = mConsole.GetSharedFolders().Enumerate();
|
---|
676 | putBackTo (en, root);
|
---|
677 | }
|
---|
678 |
|
---|
679 | void VBoxSharedFoldersSettings::putBackTo (CSharedFolderEnumerator &aEn,
|
---|
680 | Q3ListViewItem *aRoot)
|
---|
681 | {
|
---|
682 | Assert (!aRoot->text (3).isNull());
|
---|
683 | SFDialogType type = (SFDialogType)aRoot->text (3).toInt();
|
---|
684 |
|
---|
685 | /* deleting all changed folders of the list */
|
---|
686 | while (aEn.HasMore())
|
---|
687 | {
|
---|
688 | CSharedFolder sf = aEn.GetNext();
|
---|
689 |
|
---|
690 | /* Search for this root's items */
|
---|
691 | Q3ListViewItem *firstItem = aRoot->firstChild();
|
---|
692 | VBoxRichListItem *item = firstItem &&
|
---|
693 | firstItem->rtti() == VBoxRichListItem::QIRichListItemId ?
|
---|
694 | static_cast<VBoxRichListItem*> (firstItem) : 0;
|
---|
695 | while (item)
|
---|
696 | {
|
---|
697 | if (item->getText (0) == sf.GetName() &&
|
---|
698 | item->getText (1) == sf.GetHostPath() &&
|
---|
699 | item->getText (3) == "not edited")
|
---|
700 | break;
|
---|
701 | item = item->nextSibling();
|
---|
702 | }
|
---|
703 | if (item)
|
---|
704 | continue;
|
---|
705 | removeSharedFolder (sf.GetName(), sf.GetHostPath(), type);
|
---|
706 | }
|
---|
707 |
|
---|
708 | /* saving all machine related list view items */
|
---|
709 | Q3ListViewItem *iterator = aRoot->firstChild();
|
---|
710 | while (iterator)
|
---|
711 | {
|
---|
712 | VBoxRichListItem *item = 0;
|
---|
713 | if (iterator->rtti() == VBoxRichListItem::QIRichListItemId)
|
---|
714 | item = static_cast<VBoxRichListItem*> (iterator);
|
---|
715 | if (item && !item->getText (0).isNull() && !item->getText (1).isNull()
|
---|
716 | && item->getText (3) == "edited")
|
---|
717 | createSharedFolder (item->getText (0), item->getText (1),
|
---|
718 | item->getText (2) == mTrFull ? true : false, type);
|
---|
719 | iterator = iterator->nextSibling();
|
---|
720 | }
|
---|
721 | }
|
---|
722 |
|
---|
723 |
|
---|
724 | Q3ListViewItem* VBoxSharedFoldersSettings::searchRoot (bool aIsPermanent)
|
---|
725 | {
|
---|
726 | if (!aIsPermanent)
|
---|
727 | return listView->findItem (QString::number (ConsoleType), 3);
|
---|
728 | else if (mDialogType & MachineType)
|
---|
729 | return listView->findItem (QString::number (MachineType), 3);
|
---|
730 | else
|
---|
731 | return listView->findItem (QString::number (GlobalType), 3);
|
---|
732 | }
|
---|
733 |
|
---|
734 | void VBoxSharedFoldersSettings::tbAddPressed()
|
---|
735 | {
|
---|
736 | /* Make the used names list: */
|
---|
737 | SFoldersNameList usedList;
|
---|
738 | Q3ListViewItemIterator it (listView);
|
---|
739 | while (*it)
|
---|
740 | {
|
---|
741 | if ((*it)->parent() && (*it)->rtti() == VBoxRichListItem::QIRichListItemId)
|
---|
742 | {
|
---|
743 | VBoxRichListItem *item = static_cast<VBoxRichListItem*> (*it);
|
---|
744 | SFDialogType type = (SFDialogType)item->parent()->text (3).toInt();
|
---|
745 | usedList << qMakePair (item->getText (0), type);
|
---|
746 | }
|
---|
747 | ++ it;
|
---|
748 | }
|
---|
749 |
|
---|
750 | /* Invoke Add-Box Dialog */
|
---|
751 | VBoxAddSFDialog dlg (this, VBoxAddSFDialog::AddDialogType,
|
---|
752 | mDialogType & ConsoleType, usedList);
|
---|
753 | if (dlg.exec() != QDialog::Accepted)
|
---|
754 | return;
|
---|
755 | QString name = dlg.getName();
|
---|
756 | QString path = dlg.getPath();
|
---|
757 | bool isPermanent = dlg.getPermanent();
|
---|
758 | /* Shared folder's name & path could not be empty */
|
---|
759 | Assert (!name.isEmpty() && !path.isEmpty());
|
---|
760 | /* Searching root for the new listview item */
|
---|
761 | Q3ListViewItem *root = searchRoot (isPermanent);
|
---|
762 | Assert (root);
|
---|
763 | /* Appending a new listview item to the root */
|
---|
764 | VBoxRichListItem *item = new VBoxRichListItem (
|
---|
765 | VBoxRichListItem::EllipsisFile, root, name, path,
|
---|
766 | dlg.getWritable() ? mTrFull : mTrReadOnly, "edited");
|
---|
767 | /* Make the created item selected */
|
---|
768 | listView->ensureItemVisible (item);
|
---|
769 | listView->setCurrentItem (item);
|
---|
770 | processCurrentChanged (item);
|
---|
771 | listView->setFocus();
|
---|
772 |
|
---|
773 | mIsListViewChanged = true;
|
---|
774 | }
|
---|
775 |
|
---|
776 | void VBoxSharedFoldersSettings::tbEditPressed()
|
---|
777 | {
|
---|
778 | /* Make the used names list: */
|
---|
779 | SFoldersNameList usedList;
|
---|
780 | Q3ListViewItemIterator it (listView);
|
---|
781 | while (*it)
|
---|
782 | {
|
---|
783 | if ((*it)->parent() && !(*it)->isSelected() &&
|
---|
784 | (*it)->rtti() == VBoxRichListItem::QIRichListItemId)
|
---|
785 | {
|
---|
786 | VBoxRichListItem *item = static_cast<VBoxRichListItem*> (*it);
|
---|
787 | SFDialogType type = (SFDialogType)item->parent()->text (3).toInt();
|
---|
788 | usedList << qMakePair (item->getText (0), type);
|
---|
789 | }
|
---|
790 | ++ it;
|
---|
791 | }
|
---|
792 |
|
---|
793 | /* Check selected item */
|
---|
794 | Q3ListViewItem *selectedItem = listView->selectedItem();
|
---|
795 | VBoxRichListItem *item =
|
---|
796 | selectedItem->rtti() == VBoxRichListItem::QIRichListItemId ?
|
---|
797 | static_cast<VBoxRichListItem*> (selectedItem) : 0;
|
---|
798 | Assert (item);
|
---|
799 | Assert (item->parent());
|
---|
800 | /* Invoke Edit-Box Dialog */
|
---|
801 | VBoxAddSFDialog dlg (this, VBoxAddSFDialog::EditDialogType,
|
---|
802 | mDialogType & ConsoleType, usedList);
|
---|
803 | dlg.setPath (item->getText (1));
|
---|
804 | dlg.setName (item->getText (0));
|
---|
805 | dlg.setPermanent ((SFDialogType)item->parent()->text (3).toInt()
|
---|
806 | != ConsoleType);
|
---|
807 | dlg.setWritable (item->getText (2) == mTrFull);
|
---|
808 | if (dlg.exec() != QDialog::Accepted)
|
---|
809 | return;
|
---|
810 | QString name = dlg.getName();
|
---|
811 | QString path = dlg.getPath();
|
---|
812 | bool isPermanent = dlg.getPermanent();
|
---|
813 | /* Shared folder's name & path could not be empty */
|
---|
814 | Assert (!name.isEmpty() && !path.isEmpty());
|
---|
815 | /* Searching new root for the selected listview item */
|
---|
816 | Q3ListViewItem *root = searchRoot (isPermanent);
|
---|
817 | Assert (root);
|
---|
818 | /* Updating an edited listview item */
|
---|
819 | item->updateText (3, "edited");
|
---|
820 | item->updateText (2, dlg.getWritable() ? mTrFull : mTrReadOnly);
|
---|
821 | item->updateText (1, path);
|
---|
822 | item->updateText (0, name);
|
---|
823 | if (item->parent() != root)
|
---|
824 | {
|
---|
825 | /* Move the selected item into new location */
|
---|
826 | item->parent()->takeItem (item);
|
---|
827 | root->insertItem (item);
|
---|
828 |
|
---|
829 | /* Make the created item selected */
|
---|
830 | listView->ensureItemVisible (item);
|
---|
831 | listView->setCurrentItem (item);
|
---|
832 | processCurrentChanged (item);
|
---|
833 | listView->setFocus();
|
---|
834 | }
|
---|
835 | item->repaint();
|
---|
836 |
|
---|
837 | mIsListViewChanged = true;
|
---|
838 | }
|
---|
839 |
|
---|
840 | void VBoxSharedFoldersSettings::tbRemovePressed()
|
---|
841 | {
|
---|
842 | Assert (listView->selectedItem());
|
---|
843 | delete listView->selectedItem();
|
---|
844 | mIsListViewChanged = true;
|
---|
845 | }
|
---|
846 |
|
---|
847 |
|
---|
848 | void VBoxSharedFoldersSettings::processCurrentChanged (Q3ListViewItem *aItem)
|
---|
849 | {
|
---|
850 | if (aItem && aItem->isSelectable() && listView->selectedItem() != aItem)
|
---|
851 | listView->setSelected (aItem, true);
|
---|
852 | bool addEnabled = aItem &&
|
---|
853 | (isEditable (aItem->text (3)) ||
|
---|
854 | (aItem->parent() && isEditable (aItem->parent()->text (3))));
|
---|
855 | bool removeEnabled = aItem && aItem->parent() &&
|
---|
856 | isEditable (aItem->parent()->text (3));
|
---|
857 | tbAdd->setEnabled (addEnabled);
|
---|
858 | tbEdit->setEnabled (removeEnabled);
|
---|
859 | tbRemove->setEnabled (removeEnabled);
|
---|
860 | }
|
---|
861 |
|
---|
862 | void VBoxSharedFoldersSettings::processDoubleClick (Q3ListViewItem *aItem)
|
---|
863 | {
|
---|
864 | bool editEnabled = aItem && aItem->parent() &&
|
---|
865 | isEditable (aItem->parent()->text (3));
|
---|
866 | if (editEnabled)
|
---|
867 | tbEditPressed();
|
---|
868 | }
|
---|
869 |
|
---|
870 | bool VBoxSharedFoldersSettings::isEditable (const QString &aKey)
|
---|
871 | {
|
---|
872 | /* mDialogType should be setup already */
|
---|
873 | Assert (mDialogType);
|
---|
874 |
|
---|
875 | SFDialogType type = (SFDialogType)aKey.toInt();
|
---|
876 | if (!type) return false;
|
---|
877 | return mDialogType & type;
|
---|
878 | }
|
---|
879 |
|
---|
880 |
|
---|
881 | #include "VBoxSharedFoldersSettings.ui.moc"
|
---|