VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h@ 8225

Last change on this file since 8225 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette