VirtualBox

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

Last change on this file since 6719 was 6656, checked in by vboxsync, 17 years ago

FE/Qt: Shared Folder UI: "Writable" => "Read-only".

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

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