VirtualBox

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

Last change on this file since 1011 was 973, checked in by vboxsync, 18 years ago

FE/Qt: Spelling.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.1 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 InnoTek Systemberatung 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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
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
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 QListViewItem (aParent, aName, aPath), mFormat (aFormat)
61 {
62 mTextList << aName << aPath;
63 }
64
65 int rtti() const { return QIRichListItemId; }
66
67 QString getText (int aIndex)
68 {
69 return aIndex >= 0 && aIndex < (int)mTextList.size() ?
70 mTextList [aIndex] : QString::null;
71 }
72
73protected:
74
75 void paintCell (QPainter *aPainter, const QColorGroup &aColorGroup,
76 int aColumn, int aWidth, int aAlign)
77 {
78 processColumn (aColumn, aWidth);
79 QListViewItem::paintCell (aPainter, aColorGroup, aColumn, aWidth, aAlign);
80 }
81
82 void processColumn (int aColumn, int aWidth)
83 {
84 QString oneString = aColumn >= 0 && aColumn < (int)mTextList.size() ?
85 mTextList [aColumn] : QString::null;
86 if (oneString.isNull())
87 return;
88 int oldSize = listView()->fontMetrics().width (oneString);
89 int indentSize = listView()->fontMetrics().width ("...x");
90
91 /* compress text */
92 int start = 0;
93 int finish = 0;
94 int position = 0;
95 int textWidth = 0;
96 do {
97 textWidth = listView()->fontMetrics().width (oneString);
98 if (textWidth + indentSize > aWidth)
99 {
100 start = 0;
101 finish = oneString.length();
102
103 /* selecting remove position */
104 switch (mFormat)
105 {
106 case EllipsisStart:
107 position = start;
108 break;
109 case EllipsisMiddle:
110 position = (finish - start) / 2;
111 break;
112 case EllipsisEnd:
113 position = finish - 1;
114 break;
115 case EllipsisFile:
116 {
117 QRegExp regExp ("([\\\\/][^\\\\^/]+[\\\\/]?$)");
118 int newFinish = regExp.search (oneString);
119 if (newFinish != -1)
120 finish = newFinish;
121 position = (finish - start) / 2;
122 break;
123 }
124 default:
125 AssertMsgFailed (("Invalid format type\n"));
126 }
127
128 if (position == finish)
129 break;
130 oneString.remove (position, 1);
131 }
132 } while (textWidth + indentSize > aWidth);
133 if (position || mFormat == EllipsisFile) oneString.insert (position, "...");
134
135 int newSize = listView()->fontMetrics().width (oneString);
136 setText (aColumn, newSize < oldSize ? oneString : mTextList [aColumn]);
137 }
138
139 FormatType mFormat;
140 QStringList mTextList;
141};
142
143
144class VBoxAddSFDialog : public QDialog
145{
146 Q_OBJECT
147
148public:
149
150 VBoxAddSFDialog (QWidget *aParent) :
151 QDialog (aParent, "VBoxAddSFDialog", true /* modal */),
152 mLePath (0), mLeName (0)
153 {
154 setCaption (tr ("Add Share"));
155 QVBoxLayout *mainLayout = new QVBoxLayout (this, 10, 10, "mainLayout");
156
157 /* Setup Input layout */
158 QGridLayout *inputLayout = new QGridLayout (mainLayout, 2, 3, 10, "inputLayout");
159 QLabel *lbPath = new QLabel ("Folder Path", this);
160 mLePath = new QLineEdit (this);
161 QToolButton *tbPath = new QToolButton (this);
162 QLabel *lbName = new QLabel ("Folder Name", this);
163 mLeName = new QLineEdit (this);
164 tbPath->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
165 "select_file_dis_16px.png"));
166 tbPath->setFocusPolicy (QWidget::TabFocus);
167 connect (mLePath, SIGNAL (textChanged (const QString &)),
168 this, SLOT (validate()));
169 connect (mLeName, SIGNAL (textChanged (const QString &)),
170 this, SLOT (validate()));
171 connect (tbPath, SIGNAL (clicked()), this, SLOT (showFileDialog()));
172 QWhatsThis::add (mLePath, tr ("Enter existing path for the shared folder here"));
173 QWhatsThis::add (mLeName, tr ("Enter name for the shared folder to be created"));
174 QWhatsThis::add (tbPath, tr ("Click to invoke <open folder> dialog"));
175
176 inputLayout->addWidget (lbPath, 0, 0);
177 inputLayout->addWidget (mLePath, 0, 1);
178 inputLayout->addWidget (tbPath, 0, 2);
179 inputLayout->addWidget (lbName, 1, 0);
180 inputLayout->addMultiCellWidget (mLeName, 1, 1, 1, 2);
181
182 /* Setup Button layout */
183 QHBoxLayout *buttonLayout = new QHBoxLayout (mainLayout, 10, "buttonLayout");
184 mBtOk = new QPushButton ("OK", this, "btOk");
185 QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
186 QPushButton *btCancel = new QPushButton ("Cancel", this, "btCancel");
187 connect (mBtOk, SIGNAL (clicked()), this, SLOT (accept()));
188 connect (btCancel, SIGNAL (clicked()), this, SLOT (reject()));
189
190 buttonLayout->addWidget (mBtOk);
191 buttonLayout->addItem (spacer);
192 buttonLayout->addWidget (btCancel);
193
194 /* Validate fields */
195 validate();
196 }
197
198 ~VBoxAddSFDialog() {}
199
200 QString getPath() { return mLePath->text(); }
201
202 QString getName() { return mLeName->text(); }
203
204private slots:
205
206 void validate()
207 {
208 mBtOk->setEnabled (!mLePath->text().isEmpty() && !mLeName->text().isEmpty());
209 }
210
211 void showFileDialog()
212 {
213 QFileDialog dlg (QDir::rootDirPath(), QString::null, this);
214 dlg.setMode (QFileDialog::DirectoryOnly);
215 dlg.setCaption (tr ("Select a folder to share"));
216 if (dlg.exec() == QDialog::Accepted)
217 {
218 QString folderName = QDir::convertSeparators (dlg.selectedFile());
219 QRegExp commonRule ("[\\\\/]([^\\\\^/]+)[\\\\/]?$");
220 QRegExp rootRule ("(([a-zA-Z])[^\\\\^/])?[\\\\/]$");
221 if (commonRule.search (folderName) != -1)
222 {
223 /* processing non-root folder */
224 mLePath->setText (folderName.remove (QRegExp ("[\\\\/]$")));
225 mLeName->setText (commonRule.cap (1));
226 }
227 else if (rootRule.search (folderName) != -1)
228 {
229 /* processing root folder */
230 mLePath->setText (folderName);
231#if defined(Q_WS_WIN32)
232 mLeName->setText (rootRule.cap (2) + "_DRIVE");
233#elif defined(Q_WS_X11)
234 mLeName->setText ("ROOT");
235#endif
236 }
237 else
238 return; /* hm, what type of folder it was? */
239 }
240 }
241
242private:
243
244 void showEvent (QShowEvent *aEvent)
245 {
246 setFixedHeight (height());
247 QDialog::showEvent (aEvent);
248 }
249
250 QPushButton *mBtOk;
251 QLineEdit *mLePath;
252 QLineEdit *mLeName;
253};
254
255
256void VBoxSharedFoldersSettings::init()
257{
258 mDialogType = WrongType;
259 new QIListViewSelectionPreserver (this, listView);
260 listView->setShowToolTips (false);
261 listView->setRootIsDecorated (true);
262 tbAdd->setIconSet (VBoxGlobal::iconSet ("select_file_16px.png",
263 "select_file_dis_16px.png"));
264 tbRemove->setIconSet (VBoxGlobal::iconSet ("eraser_16px.png",
265 "eraser_disabled_16px.png"));
266 connect (tbAdd, SIGNAL (clicked()), this, SLOT (tbAddPressed()));
267 connect (tbRemove, SIGNAL (clicked()), this, SLOT (tbRemovePressed()));
268 connect (listView, SIGNAL (currentChanged (QListViewItem *)),
269 this, SLOT (processCurrentChanged (QListViewItem *)));
270 connect (listView, SIGNAL (onItem (QListViewItem *)),
271 this, SLOT (processOnItem (QListViewItem *)));
272
273 mIsListViewChanged = false;
274}
275
276void VBoxSharedFoldersSettings::setDialogType (
277 VBoxSharedFoldersSettings::SFDialogType aType)
278{
279 mDialogType = aType;
280}
281
282
283void VBoxSharedFoldersSettings::removeSharedFolder (const QString & aName,
284 const QString & aPath,
285 SFDialogType aType)
286{
287 switch (aType)
288 {
289 case GlobalType:
290 {
291 /* This feature is not implemented yet */
292 AssertMsgFailed (("Global shared folders are not implemented yet\n"));
293 break;
294 }
295 case MachineType:
296 {
297 Assert (!mMachine.isNull());
298 mMachine.RemoveSharedFolder (aName);
299 if (!mMachine.isOk())
300 vboxProblem().cannotRemoveSharedFolder (this, mMachine,
301 aName, aPath);
302 break;
303 }
304 case ConsoleType:
305 {
306 Assert (!mConsole.isNull());
307 mConsole.RemoveSharedFolder (aName);
308 if (!mConsole.isOk())
309 vboxProblem().cannotRemoveSharedFolder (this, mConsole,
310 aName, aPath);
311 break;
312 }
313 default:
314 {
315 AssertMsgFailed (("Incorrect shared folder type\n"));
316 }
317 }
318}
319
320void VBoxSharedFoldersSettings::createSharedFolder (const QString & aName,
321 const QString & aPath,
322 SFDialogType aType)
323{
324 switch (aType)
325 {
326 case GlobalType:
327 {
328 /* This feature is not implemented yet */
329 AssertMsgFailed (("Global shared folders are not implemented yet\n"));
330 break;
331 }
332 case MachineType:
333 {
334 Assert (!mMachine.isNull());
335 mMachine.CreateSharedFolder (aName, aPath);
336 if (!mMachine.isOk())
337 vboxProblem().cannotCreateSharedFolder (this, mMachine,
338 aName, aPath);
339 break;
340 }
341 case ConsoleType:
342 {
343 Assert (!mConsole.isNull());
344 mConsole.CreateSharedFolder (aName, aPath);
345 if (!mConsole.isOk())
346 vboxProblem().cannotCreateSharedFolder (this, mConsole,
347 aName, aPath);
348 break;
349 }
350 default:
351 {
352 AssertMsgFailed (("Incorrect shared folder type\n"));
353 }
354 }
355}
356
357
358void VBoxSharedFoldersSettings::getFromGlobal()
359{
360 /* This feature is not implemented yet */
361 AssertMsgFailed (("Global shared folders are not implemented yet\n"));
362
363 /*
364 QString name = tr (" Global Folders");
365 QString key (QString::number (GlobalType));
366 VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
367 listView, name, QString::null, key);
368 getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate(), root);
369 */
370}
371
372void VBoxSharedFoldersSettings::getFromMachine (const CMachine &aMachine)
373{
374 mMachine = aMachine;
375 QString name = tr (" Machine Folders");
376 QString key (QString::number (MachineType));
377 VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
378 listView, name, QString::null, key);
379 getFrom (mMachine.GetSharedFolders().Enumerate(), root);
380}
381
382void VBoxSharedFoldersSettings::getFromConsole (const CConsole &aConsole)
383{
384 mConsole = aConsole;
385 QString name = tr (" Transient Folders");
386 QString key (QString::number (ConsoleType));
387 VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
388 listView, name, QString::null, key);
389 getFrom (mConsole.GetSharedFolders().Enumerate(), root);
390}
391
392void VBoxSharedFoldersSettings::getFrom (const CSharedFolderEnumerator &aEn,
393 QListViewItem *aRoot)
394{
395 aRoot->setSelectable (false);
396 while (aEn.HasMore())
397 {
398 CSharedFolder sf = aEn.GetNext();
399 new VBoxRichListItem (VBoxRichListItem::EllipsisFile, aRoot,
400 sf.GetName(), sf.GetHostPath());
401 }
402 listView->setOpen (aRoot, true);
403 listView->setCurrentItem (aRoot);
404 processCurrentChanged (aRoot);
405}
406
407
408void VBoxSharedFoldersSettings::putBackToGlobal()
409{
410 /* This feature is not implemented yet */
411 AssertMsgFailed (("Global shared folders are not implemented yet\n"));
412
413 /*
414 if (!mIsListViewChanged) return;
415 // This function is only available for GlobalType dialog
416 Assert (mDialogType == GlobalType);
417 // Searching for GlobalType item's root
418 QListViewItem *root = listView->findItem (QString::number (GlobalType), 2);
419 Assert (root);
420 CSharedFolderEnumerator en = vboxGlobal().virtualBox().GetSharedFolders().Enumerate();
421 putBackTo (en, root);
422 */
423}
424
425void VBoxSharedFoldersSettings::putBackToMachine()
426{
427 if (!mIsListViewChanged)
428 return;
429
430 /* This function is only available for MachineType dialog */
431 Assert (mDialogType == MachineType);
432 /* Searching for MachineType item's root */
433 QListViewItem *root = listView->findItem (QString::number (MachineType), 2);
434 Assert (root);
435 CSharedFolderEnumerator en = mMachine.GetSharedFolders().Enumerate();
436 putBackTo (en, root);
437}
438
439void VBoxSharedFoldersSettings::putBackToConsole()
440{
441 if (!mIsListViewChanged)
442 return;
443
444 /* This function is only available for ConsoleType dialog */
445 Assert (mDialogType == ConsoleType);
446 /* Searching for ConsoleType item's root */
447 QListViewItem *root = listView->findItem (QString::number (ConsoleType), 2);
448 Assert (root);
449 CSharedFolderEnumerator en = mConsole.GetSharedFolders().Enumerate();
450 putBackTo (en, root);
451}
452
453void VBoxSharedFoldersSettings::putBackTo (CSharedFolderEnumerator &aEn,
454 QListViewItem *aRoot)
455{
456 Assert (!aRoot->text (2).isNull());
457 SFDialogType type = (SFDialogType)aRoot->text (2).toInt();
458
459 /* deleting all existing folders if the list */
460 while (aEn.HasMore())
461 {
462 CSharedFolder sf = aEn.GetNext();
463 removeSharedFolder (sf.GetName(), sf.GetHostPath(), type);
464 }
465
466 /* saving all machine related list view items */
467 QListViewItem *iterator = aRoot->firstChild();
468 while (iterator)
469 {
470 VBoxRichListItem *item = 0;
471 if (iterator->rtti() == VBoxRichListItem::QIRichListItemId)
472 item = static_cast<VBoxRichListItem*> (iterator);
473 if (item && !item->getText (0).isNull() && !item->getText (1).isNull())
474 createSharedFolder (item->getText (0), item->getText (1), type);
475 else
476 AssertMsgFailed (("Incorrect listview item type\n"));
477 iterator = iterator->nextSibling();
478 }
479}
480
481
482void VBoxSharedFoldersSettings::tbAddPressed()
483{
484 /* Invoke Add-Box Dialog */
485 VBoxAddSFDialog dlg (this);
486 if (dlg.exec() != QDialog::Accepted)
487 return;
488 QString name = dlg.getName();
489 QString path = dlg.getPath();
490 /* Shared folder's name & path could not be empty */
491 Assert (!name.isEmpty() && !path.isEmpty());
492 /* Searching root for the new listview item */
493 QListViewItem *root = listView->findItem (QString::number (mDialogType), 2);
494 Assert (root);
495 /* Appending a new listview item to the root */
496 VBoxRichListItem *item = new VBoxRichListItem (VBoxRichListItem::EllipsisFile,
497 root, name, path);
498 listView->ensureItemVisible (item);
499 listView->setCurrentItem (item);
500 processCurrentChanged (item);
501 listView->setFocus();
502 mIsListViewChanged = true;
503}
504
505void VBoxSharedFoldersSettings::tbRemovePressed()
506{
507 Assert (listView->selectedItem());
508 delete listView->selectedItem();
509 mIsListViewChanged = true;
510}
511
512
513void VBoxSharedFoldersSettings::processOnItem (QListViewItem *aItem)
514{
515 VBoxRichListItem *item = 0;
516 if (aItem->rtti() == VBoxRichListItem::QIRichListItemId)
517 item = static_cast<VBoxRichListItem*> (aItem);
518 Assert (item);
519 QString tip = tr ("<nobr>Name:&nbsp;&nbsp;%1</nobr><br>"
520 "<nobr>Path:&nbsp;&nbsp;%2</nobr>")
521 .arg (item->getText (0)).arg (item->getText (1));
522 if (!item->getText (0).isNull() && !item->getText (1).isNull())
523 QToolTip::add (listView->viewport(), listView->itemRect (aItem), tip);
524 else
525 QToolTip::remove (listView->viewport());
526}
527
528void VBoxSharedFoldersSettings::processCurrentChanged (QListViewItem *aItem)
529{
530 if (aItem && aItem->isSelectable() && listView->selectedItem() != aItem)
531 listView->setSelected (aItem, true);
532 bool removeEnabled = aItem && aItem->parent() &&
533 isEditable (aItem->parent()->text (2));
534 bool addEnabled = aItem &&
535 (isEditable (aItem->text (2)) ||
536 aItem->parent() && isEditable (aItem->parent()->text (2)));
537 tbRemove->setEnabled (removeEnabled);
538 tbAdd->setEnabled (addEnabled);
539}
540
541bool VBoxSharedFoldersSettings::isEditable (const QString &aKey)
542{
543 /* mDialogType should be sutup already */
544 Assert (mDialogType);
545 /* simple item has no key information */
546 if (aKey.isEmpty())
547 return false;
548 SFDialogType type = (SFDialogType)aKey.toInt();
549 if (!type)
550 AssertMsgFailed (("Incorrect listview item key value\n"));
551 return type == mDialogType;
552}
553
554
555#include "VBoxSharedFoldersSettings.ui.moc"
556
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