~ubuntu-branches/ubuntu/trusty/virtualbox-lts-xenial/trusty-updates

« back to all changes in this revision

Viewing changes to .pc/16-no-update.patch/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp

  • Committer: Package Import Robot
  • Author(s): Gianfranco Costamagna
  • Date: 2016-02-23 14:28:26 UTC
  • Revision ID: package-import@ubuntu.com-20160223142826-kpprg3lfwn2izud0
Tags: 4.3.36-dfsg-1+deb8u1ubuntu1.14.04.1~14.04.4
Use lts-xenial stack. Build only guest additions (LP: #1424769).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: UISettingsDialogSpecific.cpp $ */
 
2
/** @file
 
3
 *
 
4
 * VBox frontends: Qt GUI ("VirtualBox"):
 
5
 * UISettingsDialogSpecific class implementation
 
6
 */
 
7
 
 
8
/*
 
9
 * Copyright (C) 2006-2012 Oracle Corporation
 
10
 *
 
11
 * This file is part of VirtualBox Open Source Edition (OSE), as
 
12
 * available from http://www.virtualbox.org. This file is free software;
 
13
 * you can redistribute it and/or modify it under the terms of the GNU
 
14
 * General Public License (GPL) as published by the Free Software
 
15
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 
16
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 
17
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 
18
 */
 
19
 
 
20
/* Qt includes: */
 
21
#include <QStackedWidget>
 
22
#include <QThread>
 
23
#include <QMutex>
 
24
#include <QWaitCondition>
 
25
#include <QTimer>
 
26
 
 
27
/* GUI includes: */
 
28
#include "UISettingsDialogSpecific.h"
 
29
#include "UISettingsDefs.h"
 
30
#include "VBoxGlobal.h"
 
31
#include "UIMessageCenter.h"
 
32
#include "QIWidgetValidator.h"
 
33
#include "VBoxSettingsSelector.h"
 
34
#include "UIVirtualBoxEventHandler.h"
 
35
 
 
36
#include "UIGlobalSettingsGeneral.h"
 
37
#include "UIGlobalSettingsInput.h"
 
38
#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
 
39
# include "UIGlobalSettingsUpdate.h"
 
40
#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
 
41
#include "UIGlobalSettingsLanguage.h"
 
42
#include "UIGlobalSettingsDisplay.h"
 
43
#include "UIGlobalSettingsNetwork.h"
 
44
#include "UIGlobalSettingsExtension.h"
 
45
#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
 
46
# include "UIGlobalSettingsProxy.h"
 
47
#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
 
48
 
 
49
#include "UIMachineSettingsGeneral.h"
 
50
#include "UIMachineSettingsSystem.h"
 
51
#include "UIMachineSettingsDisplay.h"
 
52
#include "UIMachineSettingsStorage.h"
 
53
#include "UIMachineSettingsAudio.h"
 
54
#include "UIMachineSettingsNetwork.h"
 
55
#include "UIMachineSettingsSerial.h"
 
56
#include "UIMachineSettingsParallel.h"
 
57
#include "UIMachineSettingsUSB.h"
 
58
#include "UIMachineSettingsSF.h"
 
59
 
 
60
/* COM includes: */
 
61
#include "CUSBController.h"
 
62
 
 
63
#if 0 /* Global USB filters are DISABLED now: */
 
64
# define ENABLE_GLOBAL_USB
 
65
#endif /* Global USB filters are DISABLED now: */
 
66
 
 
67
/* Settings page list: */
 
68
typedef QList<UISettingsPage*> UISettingsPageList;
 
69
typedef QMap<int, UISettingsPage*> UISettingsPageMap;
 
70
 
 
71
/* Serializer direction: */
 
72
enum UISettingsSerializeDirection
 
73
{
 
74
    UISettingsSerializeDirection_Load,
 
75
    UISettingsSerializeDirection_Save
 
76
};
 
77
 
 
78
/* QThread reimplementation for loading/saving settings in async mode: */
 
79
class UISettingsSerializer : public QThread
 
80
{
 
81
    Q_OBJECT;
 
82
 
 
83
signals:
 
84
 
 
85
    /* Signal to notify main GUI thread about process has been started: */
 
86
    void sigNotifyAboutProcessStarted();
 
87
 
 
88
    /* Signal to notify main GUI thread about some page was processed: */
 
89
    void sigNotifyAboutPageProcessed(int iPageId);
 
90
 
 
91
    /* Signal to notify main GUI thread about all pages were processed: */
 
92
    void sigNotifyAboutPagesProcessed();
 
93
 
 
94
public:
 
95
 
 
96
    /* Settings serializer instance: */
 
97
    static UISettingsSerializer* instance() { return m_pInstance; }
 
98
 
 
99
    /* Settings serializer constructor: */
 
100
    UISettingsSerializer(QObject *pParent, const QVariant &data, UISettingsSerializeDirection direction)
 
101
        : QThread(pParent)
 
102
        , m_direction(direction)
 
103
        , m_data(data)
 
104
        , m_fSavingComplete(m_direction == UISettingsSerializeDirection_Load)
 
105
        , m_fAllowToDestroySerializer(m_direction == UISettingsSerializeDirection_Load)
 
106
        , m_iIdOfHighPriorityPage(-1)
 
107
    {
 
108
        /* Set instance: */
 
109
        m_pInstance = this;
 
110
 
 
111
        /* Connecting this signals: */
 
112
        connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), this, SLOT(sltHandleProcessedPage(int)), Qt::QueuedConnection);
 
113
        connect(this, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltHandleProcessedPages()), Qt::QueuedConnection);
 
114
        connect(this, SIGNAL(finished()), this, SLOT(sltDestroySerializer()), Qt::QueuedConnection);
 
115
        /* Connecting parent signals: */
 
116
        connect(this, SIGNAL(sigNotifyAboutProcessStarted()), parent(), SLOT(sltHandleProcessStarted()), Qt::QueuedConnection);
 
117
        connect(this, SIGNAL(sigNotifyAboutPageProcessed(int)), parent(), SLOT(sltHandlePageProcessed()), Qt::QueuedConnection);
 
118
    }
 
119
 
 
120
    /* Settings serializer destructor: */
 
121
    ~UISettingsSerializer()
 
122
    {
 
123
        /* If serializer is being destructed by it's parent,
 
124
         * thread could still be running, we have to wait
 
125
         * for it to be finished! */
 
126
        if (isRunning())
 
127
            wait();
 
128
 
 
129
        /* Clear instance: */
 
130
        m_pInstance = 0;
 
131
    }
 
132
 
 
133
    /* Set pages list: */
 
134
    void setPageList(const UISettingsPageList &pageList)
 
135
    {
 
136
        for (int iPageIndex = 0; iPageIndex < pageList.size(); ++iPageIndex)
 
137
        {
 
138
            UISettingsPage *pPage = pageList[iPageIndex];
 
139
            m_pages.insert(pPage->id(), pPage);
 
140
        }
 
141
    }
 
142
 
 
143
    /* Raise priority of page: */
 
144
    void raisePriorityOfPage(int iPageId)
 
145
    {
 
146
        /* If that page is not present or was processed already: */
 
147
        if (!m_pages.contains(iPageId) || m_pages[iPageId]->processed())
 
148
        {
 
149
            /* We just ignoring that request: */
 
150
            return;
 
151
        }
 
152
        else
 
153
        {
 
154
            /* Else remember which page we should be processed next: */
 
155
            m_iIdOfHighPriorityPage = iPageId;
 
156
        }
 
157
    }
 
158
 
 
159
    /* Return current m_data content: */
 
160
    QVariant& data() { return m_data; }
 
161
 
 
162
public slots:
 
163
 
 
164
    void start(Priority priority = InheritPriority)
 
165
    {
 
166
        /* Notify listeners about we are starting: */
 
167
        emit sigNotifyAboutProcessStarted();
 
168
 
 
169
        /* If serializer saves settings: */
 
170
        if (m_direction == UISettingsSerializeDirection_Save)
 
171
        {
 
172
            /* We should update internal page cache first: */
 
173
            for (int iPageIndex = 0; iPageIndex < m_pages.values().size(); ++iPageIndex)
 
174
                m_pages.values()[iPageIndex]->putToCache();
 
175
        }
 
176
 
 
177
        /* Start async serializing thread: */
 
178
        QThread::start(priority);
 
179
 
 
180
        /* If serializer saves settings: */
 
181
        if (m_direction == UISettingsSerializeDirection_Save)
 
182
        {
 
183
            /* We should block calling thread until all pages will be saved: */
 
184
            while (!m_fSavingComplete)
 
185
            {
 
186
                /* Lock mutex initially: */
 
187
                m_mutex.lock();
 
188
                /* Perform idle-processing every 100ms,
 
189
                 * and waiting for direct wake up signal: */
 
190
                m_condition.wait(&m_mutex, 100);
 
191
                /* Process queued signals posted to GUI thread: */
 
192
                qApp->processEvents();
 
193
                /* Unlock mutex finally: */
 
194
                m_mutex.unlock();
 
195
            }
 
196
            m_fAllowToDestroySerializer = true;
 
197
        }
 
198
    }
 
199
 
 
200
protected slots:
 
201
 
 
202
    /* Slot to handle the fact of some page was processed: */
 
203
    void sltHandleProcessedPage(int iPageId)
 
204
    {
 
205
        /* If serializer loads settings: */
 
206
        if (m_direction == UISettingsSerializeDirection_Load)
 
207
        {
 
208
            /* If such page present we should fetch internal page cache: */
 
209
            if (m_pages.contains(iPageId))
 
210
            {
 
211
                UISettingsPage *pSettingsPage = m_pages[iPageId];
 
212
                pSettingsPage->setValidatorBlocked(true);
 
213
                pSettingsPage->getFromCache();
 
214
                pSettingsPage->setValidatorBlocked(false);
 
215
            }
 
216
        }
 
217
    }
 
218
 
 
219
    /* Slot to handle the fact of all pages were processed: */
 
220
    void sltHandleProcessedPages()
 
221
    {
 
222
        /* If serializer saves settings: */
 
223
        if (m_direction == UISettingsSerializeDirection_Save)
 
224
        {
 
225
            /* We should flag GUI thread to unlock itself: */
 
226
            if (!m_fSavingComplete)
 
227
                m_fSavingComplete = true;
 
228
        }
 
229
        /* If serializer loads settings: */
 
230
        else
 
231
        {
 
232
            /* We have to do initial validation finally: */
 
233
            foreach (UISettingsPage *pPage, m_pages.values())
 
234
                pPage->revalidate();
 
235
        }
 
236
    }
 
237
 
 
238
    /* Slot to destroy serializer: */
 
239
    void sltDestroySerializer()
 
240
    {
 
241
        /* If not yet all events were processed,
 
242
         * we should postpone destruction for now: */
 
243
        if (!m_fAllowToDestroySerializer)
 
244
            QTimer::singleShot(0, this, SLOT(sltDestroySerializer()));
 
245
        else
 
246
            deleteLater();
 
247
    }
 
248
 
 
249
protected:
 
250
 
 
251
    /* Settings processor: */
 
252
    void run()
 
253
    {
 
254
        /* Initialize COM for other thread: */
 
255
        COMBase::InitializeCOM(false);
 
256
 
 
257
        /* Mark all the pages initially as NOT processed: */
 
258
        QList<UISettingsPage*> pageList = m_pages.values();
 
259
        for (int iPageNumber = 0; iPageNumber < pageList.size(); ++iPageNumber)
 
260
            pageList[iPageNumber]->setProcessed(false);
 
261
 
 
262
        /* Iterate over the all left settings pages: */
 
263
        UISettingsPageMap pages(m_pages);
 
264
        while (!pages.empty())
 
265
        {
 
266
            /* Get required page pointer, protect map by mutex while getting pointer: */
 
267
            UISettingsPage *pPage = m_iIdOfHighPriorityPage != -1 && pages.contains(m_iIdOfHighPriorityPage) ?
 
268
                                    pages[m_iIdOfHighPriorityPage] : *pages.begin();
 
269
            /* Reset request of high priority: */
 
270
            if (m_iIdOfHighPriorityPage != -1)
 
271
                m_iIdOfHighPriorityPage = -1;
 
272
            /* Process this page if its enabled: */
 
273
            if (pPage->isEnabled())
 
274
            {
 
275
                if (m_direction == UISettingsSerializeDirection_Load)
 
276
                    pPage->loadToCacheFrom(m_data);
 
277
                if (m_direction == UISettingsSerializeDirection_Save)
 
278
                    pPage->saveFromCacheTo(m_data);
 
279
            }
 
280
            /* Remember what page was processed: */
 
281
            pPage->setProcessed(true);
 
282
            /* Remove processed page from our map: */
 
283
            pages.remove(pPage->id());
 
284
            /* Notify listeners about page was processed: */
 
285
            emit sigNotifyAboutPageProcessed(pPage->id());
 
286
            /* If serializer saves settings => wake up GUI thread: */
 
287
            if (m_direction == UISettingsSerializeDirection_Save)
 
288
                m_condition.wakeAll();
 
289
            /* Break further processing if page had failed: */
 
290
            if (pPage->failed())
 
291
                break;
 
292
        }
 
293
        /* Notify listeners about all pages were processed: */
 
294
        emit sigNotifyAboutPagesProcessed();
 
295
        /* If serializer saves settings => wake up GUI thread: */
 
296
        if (m_direction == UISettingsSerializeDirection_Save)
 
297
            m_condition.wakeAll();
 
298
 
 
299
        /* Deinitialize COM for other thread: */
 
300
        COMBase::CleanupCOM();
 
301
    }
 
302
 
 
303
    /* Variables: */
 
304
    UISettingsSerializeDirection m_direction;
 
305
    QVariant m_data;
 
306
    UISettingsPageMap m_pages;
 
307
    bool m_fSavingComplete;
 
308
    bool m_fAllowToDestroySerializer;
 
309
    int m_iIdOfHighPriorityPage;
 
310
    QMutex m_mutex;
 
311
    QWaitCondition m_condition;
 
312
    static UISettingsSerializer *m_pInstance;
 
313
};
 
314
 
 
315
UISettingsSerializer* UISettingsSerializer::m_pInstance = 0;
 
316
 
 
317
UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent)
 
318
    : UISettingsDialog(pParent)
 
319
{
 
320
    /* Window icon: */
 
321
#ifndef Q_WS_MAC
 
322
    setWindowIcon(QIcon(":/global_settings_16px.png"));
 
323
#endif /* !Q_WS_MAC */
 
324
 
 
325
    /* Assign default dialog type: */
 
326
    setDialogType(SettingsDialogType_Offline);
 
327
 
 
328
    /* Creating settings pages: */
 
329
    CVirtualBox vbox = vboxGlobal().virtualBox();
 
330
    QList<GlobalSettingsPageType> restrictedGlobalSettingsPages = vboxGlobal().restrictedGlobalSettingsPages(vbox);
 
331
    for (int iPageIndex = GlobalSettingsPageType_General; iPageIndex < GlobalSettingsPageType_Max; ++iPageIndex)
 
332
    {
 
333
        /* Make sure page was not restricted: */
 
334
        if (restrictedGlobalSettingsPages.contains(static_cast<GlobalSettingsPageType>(iPageIndex)))
 
335
            continue;
 
336
 
 
337
        /* Make sure page is available: */
 
338
        if (isPageAvailable(iPageIndex))
 
339
        {
 
340
            UISettingsPage *pSettingsPage = 0;
 
341
            switch (iPageIndex)
 
342
            {
 
343
                /* General page: */
 
344
                case GlobalSettingsPageType_General:
 
345
                {
 
346
                    pSettingsPage = new UIGlobalSettingsGeneral;
 
347
                    addItem(":/machine_32px.png", ":/machine_disabled_32px.png",
 
348
                            ":/machine_16px.png", ":/machine_disabled_16px.png",
 
349
                            iPageIndex, "#general", pSettingsPage);
 
350
                    break;
 
351
                }
 
352
                /* Input page: */
 
353
                case GlobalSettingsPageType_Input:
 
354
                {
 
355
                    pSettingsPage = new UIGlobalSettingsInput;
 
356
                    addItem(":/hostkey_32px.png", ":/hostkey_disabled_32px.png",
 
357
                            ":/hostkey_16px.png", ":/hostkey_disabled_16px.png",
 
358
                            iPageIndex, "#input", pSettingsPage);
 
359
                    break;
 
360
                }
 
361
#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
 
362
                /* Update page: */
 
363
                case GlobalSettingsPageType_Update:
 
364
                {
 
365
                    pSettingsPage = new UIGlobalSettingsUpdate;
 
366
                    addItem(":/refresh_32px.png", ":/refresh_disabled_32px.png",
 
367
                            ":/refresh_16px.png", ":/refresh_disabled_16px.png",
 
368
                            iPageIndex, "#update", pSettingsPage);
 
369
                    break;
 
370
                }
 
371
#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
 
372
                /* Language page: */
 
373
                case GlobalSettingsPageType_Language:
 
374
                {
 
375
                    pSettingsPage = new UIGlobalSettingsLanguage;
 
376
                    addItem(":/site_32px.png", ":/site_disabled_32px.png",
 
377
                            ":/site_16px.png", ":/site_disabled_16px.png",
 
378
                            iPageIndex, "#language", pSettingsPage);
 
379
                    break;
 
380
                }
 
381
                /* Display page: */
 
382
                case GlobalSettingsPageType_Display:
 
383
                {
 
384
                    pSettingsPage = new UIGlobalSettingsDisplay;
 
385
                    addItem(":/vrdp_32px.png", ":/vrdp_disabled_32px.png",
 
386
                            ":/vrdp_16px.png", ":/vrdp_disabled_16px.png",
 
387
                            iPageIndex, "#display", pSettingsPage);
 
388
                    break;
 
389
                }
 
390
                /* Network page: */
 
391
                case GlobalSettingsPageType_Network:
 
392
                {
 
393
                    pSettingsPage = new UIGlobalSettingsNetwork;
 
394
                    addItem(":/nw_32px.png", ":/nw_disabled_32px.png",
 
395
                            ":/nw_16px.png", ":/nw_disabled_16px.png",
 
396
                            iPageIndex, "#network", pSettingsPage);
 
397
                    break;
 
398
                }
 
399
                /* Extensions page: */
 
400
                case GlobalSettingsPageType_Extensions:
 
401
                {
 
402
                    pSettingsPage = new UIGlobalSettingsExtension;
 
403
                    addItem(":/extension_pack_32px.png", ":/extension_pack_disabled_32px.png",
 
404
                            ":/extension_pack_16px.png", ":/extension_pack_disabled_16px.png",
 
405
                            iPageIndex, "#extensions", pSettingsPage);
 
406
                    break;
 
407
                }
 
408
#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
 
409
                /* Proxy page: */
 
410
                case GlobalSettingsPageType_Proxy:
 
411
                {
 
412
                    pSettingsPage = new UIGlobalSettingsProxy;
 
413
                    addItem(":/proxy_32px.png", ":/proxy_disabled_32px.png",
 
414
                            ":/proxy_16px.png", ":/proxy_disabled_16px.png",
 
415
                            iPageIndex, "#proxy", pSettingsPage);
 
416
                    break;
 
417
                }
 
418
#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
 
419
                default:
 
420
                    break;
 
421
            }
 
422
            if (pSettingsPage)
 
423
                pSettingsPage->setDialogType(dialogType());
 
424
        }
 
425
    }
 
426
 
 
427
    /* Retranslate UI: */
 
428
    retranslateUi();
 
429
 
 
430
    /* Choose first item by default: */
 
431
    m_pSelector->selectById(GlobalSettingsPageType_General);
 
432
}
 
433
 
 
434
UISettingsDialogGlobal::~UISettingsDialogGlobal()
 
435
{
 
436
    /* Delete serializer early if exists: */
 
437
    if (UISettingsSerializer::instance())
 
438
        delete UISettingsSerializer::instance();
 
439
}
 
440
 
 
441
void UISettingsDialogGlobal::loadData()
 
442
{
 
443
    /* Call for base-class: */
 
444
    UISettingsDialog::loadData();
 
445
 
 
446
    /* Prepare global data: */
 
447
    qRegisterMetaType<UISettingsDataGlobal>();
 
448
    UISettingsDataGlobal data(vboxGlobal().virtualBox().GetSystemProperties(), vboxGlobal().settings());
 
449
    /* Create global settings loader,
 
450
     * it will load global settings & delete itself in the appropriate time: */
 
451
    UISettingsSerializer *pGlobalSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
 
452
    connect(pGlobalSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded()));
 
453
    /* Set pages to be loaded: */
 
454
    pGlobalSettingsLoader->setPageList(m_pSelector->settingPages());
 
455
    /* Start loader: */
 
456
    pGlobalSettingsLoader->start();
 
457
}
 
458
 
 
459
void UISettingsDialogGlobal::saveData()
 
460
{
 
461
    /* Call for base-class: */
 
462
    UISettingsDialog::saveData();
 
463
 
 
464
    /* Get properties and settings: */
 
465
    CSystemProperties properties = vboxGlobal().virtualBox().GetSystemProperties();
 
466
    VBoxGlobalSettings settings = vboxGlobal().settings();
 
467
    /* Prepare global data: */
 
468
    qRegisterMetaType<UISettingsDataGlobal>();
 
469
    UISettingsDataGlobal data(properties, settings);
 
470
    /* Create global settings saver,
 
471
     * it will save global settings & delete itself in the appropriate time: */
 
472
    UISettingsSerializer *pGlobalSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
 
473
    /* Set pages to be saved: */
 
474
    pGlobalSettingsSaver->setPageList(m_pSelector->settingPages());
 
475
    /* Start saver: */
 
476
    pGlobalSettingsSaver->start();
 
477
 
 
478
    /* Get updated properties & settings: */
 
479
    CSystemProperties newProperties = pGlobalSettingsSaver->data().value<UISettingsDataGlobal>().m_properties;
 
480
    VBoxGlobalSettings newSettings = pGlobalSettingsSaver->data().value<UISettingsDataGlobal>().m_settings;
 
481
    /* If properties are not OK => show the error: */
 
482
    if (!newProperties.isOk())
 
483
        msgCenter().cannotSetSystemProperties(newProperties, this);
 
484
    /* Else save the new settings if they were changed: */
 
485
    else if (!(newSettings == settings))
 
486
        vboxGlobal().setSettings(newSettings);
 
487
 
 
488
    /* Mark page processed: */
 
489
    sltMarkSaved();
 
490
}
 
491
 
 
492
void UISettingsDialogGlobal::retranslateUi()
 
493
{
 
494
    /* General page: */
 
495
    m_pSelector->setItemText(GlobalSettingsPageType_General, tr("General"));
 
496
 
 
497
    /* Input page: */
 
498
    m_pSelector->setItemText(GlobalSettingsPageType_Input, tr("Input"));
 
499
 
 
500
#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
 
501
    /* Update page: */
 
502
    m_pSelector->setItemText(GlobalSettingsPageType_Update, tr("Update"));
 
503
#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
 
504
 
 
505
    /* Language page: */
 
506
    m_pSelector->setItemText(GlobalSettingsPageType_Language, tr("Language"));
 
507
 
 
508
    /* Display page: */
 
509
    m_pSelector->setItemText(GlobalSettingsPageType_Display, tr("Display"));
 
510
 
 
511
    /* Network page: */
 
512
    m_pSelector->setItemText(GlobalSettingsPageType_Network, tr("Network"));
 
513
 
 
514
    /* Extension page: */
 
515
    m_pSelector->setItemText(GlobalSettingsPageType_Extensions, tr("Extensions"));
 
516
 
 
517
#ifdef VBOX_GUI_WITH_NETWORK_MANAGER
 
518
    /* Proxy page: */
 
519
    m_pSelector->setItemText(GlobalSettingsPageType_Proxy, tr("Proxy"));
 
520
#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
 
521
 
 
522
    /* Polish the selector: */
 
523
    m_pSelector->polish();
 
524
 
 
525
    /* Base-class UI translation: */
 
526
    UISettingsDialog::retranslateUi();
 
527
 
 
528
    /* Set dialog's name: */
 
529
    setWindowTitle(title());
 
530
}
 
531
 
 
532
QString UISettingsDialogGlobal::title() const
 
533
{
 
534
    return tr("VirtualBox - %1").arg(titleExtension());
 
535
}
 
536
 
 
537
bool UISettingsDialogGlobal::isPageAvailable(int iPageId)
 
538
{
 
539
    switch (iPageId)
 
540
    {
 
541
        case GlobalSettingsPageType_Network:
 
542
        {
 
543
#ifndef VBOX_WITH_NETFLT
 
544
            return false;
 
545
#endif /* !VBOX_WITH_NETFLT */
 
546
            break;
 
547
        }
 
548
        default:
 
549
            break;
 
550
    }
 
551
    return true;
 
552
}
 
553
 
 
554
UISettingsDialogMachine::UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
 
555
                                                 const QString &strCategory, const QString &strControl)
 
556
    : UISettingsDialog(pParent)
 
557
    , m_strMachineId(strMachineId)
 
558
    , m_fAllowResetFirstRunFlag(false)
 
559
    , m_fResetFirstRunFlag(false)
 
560
{
 
561
    /* Window icon: */
 
562
#ifndef Q_WS_MAC
 
563
    setWindowIcon(QIcon(":/vm_settings_16px.png"));
 
564
#endif /* Q_WS_MAC */
 
565
 
 
566
    /* Allow to reset first-run flag just when medium enumeration was finished: */
 
567
    connect(&vboxGlobal(), SIGNAL(sigMediumEnumerationFinished()), this, SLOT(sltAllowResetFirstRunFlag()));
 
568
 
 
569
    /* Get corresponding machine (required to determine dialog type and page availability): */
 
570
    m_machine = vboxGlobal().virtualBox().FindMachine(m_strMachineId);
 
571
    AssertMsg(!m_machine.isNull(), ("Can't find corresponding machine!\n"));
 
572
    m_sessionState = m_machine.GetSessionState();
 
573
    m_machineState = m_machine.GetState();
 
574
    /* Recalculate current dialog-type: */
 
575
    updateDialogType();
 
576
 
 
577
    /* Creating settings pages: */
 
578
    QList<MachineSettingsPageType> restrictedMachineSettingsPages = vboxGlobal().restrictedMachineSettingsPages(m_machine);
 
579
    for (int iPageIndex = MachineSettingsPageType_General; iPageIndex < MachineSettingsPageType_Max; ++iPageIndex)
 
580
    {
 
581
        /* Make sure page was not restricted: */
 
582
        if (restrictedMachineSettingsPages.contains(static_cast<MachineSettingsPageType>(iPageIndex)))
 
583
            continue;
 
584
 
 
585
        /* Make sure page is available: */
 
586
        if (isPageAvailable(iPageIndex))
 
587
        {
 
588
            UISettingsPage *pSettingsPage = 0;
 
589
            switch (iPageIndex)
 
590
            {
 
591
                /* General page: */
 
592
                case MachineSettingsPageType_General:
 
593
                {
 
594
                    pSettingsPage = new UIMachineSettingsGeneral;
 
595
                    addItem(":/machine_32px.png", ":/machine_disabled_32px.png",
 
596
                            ":/machine_16px.png", ":/machine_disabled_16px.png",
 
597
                            iPageIndex, "#general", pSettingsPage);
 
598
                    break;
 
599
                }
 
600
                /* System page: */
 
601
                case MachineSettingsPageType_System:
 
602
                {
 
603
                    pSettingsPage = new UIMachineSettingsSystem;
 
604
                    addItem(":/chipset_32px.png", ":/chipset_disabled_32px.png",
 
605
                            ":/chipset_16px.png", ":/chipset_disabled_16px.png",
 
606
                            iPageIndex, "#system", pSettingsPage);
 
607
                    break;
 
608
                }
 
609
                /* Display page: */
 
610
                case MachineSettingsPageType_Display:
 
611
                {
 
612
                    pSettingsPage = new UIMachineSettingsDisplay;
 
613
                    addItem(":/vrdp_32px.png", ":/vrdp_disabled_32px.png",
 
614
                            ":/vrdp_16px.png", ":/vrdp_disabled_16px.png",
 
615
                            iPageIndex, "#display", pSettingsPage);
 
616
                    break;
 
617
                }
 
618
                /* Storage page: */
 
619
                case MachineSettingsPageType_Storage:
 
620
                {
 
621
                    pSettingsPage = new UIMachineSettingsStorage;
 
622
                    connect(pSettingsPage, SIGNAL(storageChanged()), this, SLOT(sltResetFirstRunFlag()));
 
623
                    addItem(":/hd_32px.png", ":/hd_disabled_32px.png",
 
624
                            ":/hd_16px.png", ":/hd_disabled_16px.png",
 
625
                            iPageIndex, "#storage", pSettingsPage);
 
626
                    break;
 
627
                }
 
628
                /* Audio page: */
 
629
                case MachineSettingsPageType_Audio:
 
630
                {
 
631
                    pSettingsPage = new UIMachineSettingsAudio;
 
632
                    addItem(":/sound_32px.png", ":/sound_disabled_32px.png",
 
633
                            ":/sound_16px.png", ":/sound_disabled_16px.png",
 
634
                            iPageIndex, "#audio", pSettingsPage);
 
635
                    break;
 
636
                }
 
637
                /* Network page: */
 
638
                case MachineSettingsPageType_Network:
 
639
                {
 
640
                    pSettingsPage = new UIMachineSettingsNetworkPage;
 
641
                    addItem(":/nw_32px.png", ":/nw_disabled_32px.png",
 
642
                            ":/nw_16px.png", ":/nw_disabled_16px.png",
 
643
                            iPageIndex, "#network", pSettingsPage);
 
644
                    break;
 
645
                }
 
646
                /* Ports page: */
 
647
                case MachineSettingsPageType_Ports:
 
648
                {
 
649
                    addItem(":/serial_port_32px.png", ":/serial_port_disabled_32px.png",
 
650
                            ":/serial_port_16px.png", ":/serial_port_disabled_16px.png",
 
651
                            iPageIndex, "#ports");
 
652
                    break;
 
653
                }
 
654
                /* Serial page: */
 
655
                case MachineSettingsPageType_Serial:
 
656
                {
 
657
                    pSettingsPage = new UIMachineSettingsSerialPage;
 
658
                    addItem(":/serial_port_32px.png", ":/serial_port_disabled_32px.png",
 
659
                            ":/serial_port_16px.png", ":/serial_port_disabled_16px.png",
 
660
                            iPageIndex, "#serialPorts", pSettingsPage, MachineSettingsPageType_Ports);
 
661
                    break;
 
662
                }
 
663
                /* Parallel page: */
 
664
                case MachineSettingsPageType_Parallel:
 
665
                {
 
666
                    pSettingsPage = new UIMachineSettingsParallelPage;
 
667
                    addItem(":/parallel_port_32px.png", ":/parallel_port_disabled_32px.png",
 
668
                            ":/parallel_port_16px.png", ":/parallel_port_disabled_16px.png",
 
669
                            iPageIndex, "#parallelPorts", pSettingsPage, MachineSettingsPageType_Ports);
 
670
                    break;
 
671
                }
 
672
                /* USB page: */
 
673
                case MachineSettingsPageType_USB:
 
674
                {
 
675
                    pSettingsPage = new UIMachineSettingsUSB;
 
676
                    addItem(":/usb_32px.png", ":/usb_disabled_32px.png",
 
677
                            ":/usb_16px.png", ":/usb_disabled_16px.png",
 
678
                            iPageIndex, "#usb", pSettingsPage, MachineSettingsPageType_Ports);
 
679
                    break;
 
680
                }
 
681
                /* Shared Folders page: */
 
682
                case MachineSettingsPageType_SF:
 
683
                {
 
684
                    pSettingsPage = new UIMachineSettingsSF;
 
685
                    addItem(":/sf_32px.png", ":/sf_disabled_32px.png",
 
686
                            ":/sf_16px.png", ":/sf_disabled_16px.png",
 
687
                            iPageIndex, "#sharedFolders", pSettingsPage);
 
688
                    break;
 
689
                }
 
690
                default:
 
691
                    break;
 
692
            }
 
693
            if (pSettingsPage)
 
694
                pSettingsPage->setDialogType(dialogType());
 
695
        }
 
696
    }
 
697
 
 
698
    /* Retranslate UI: */
 
699
    retranslateUi();
 
700
 
 
701
    /* Setup settings window: */
 
702
    if (!strCategory.isNull())
 
703
    {
 
704
        m_pSelector->selectByLink(strCategory);
 
705
        /* Search for a widget with the given name: */
 
706
        if (!strControl.isNull())
 
707
        {
 
708
            if (QWidget *pWidget = m_pStack->currentWidget()->findChild<QWidget*>(strControl))
 
709
            {
 
710
                QList<QWidget*> parents;
 
711
                QWidget *pParentWidget = pWidget;
 
712
                while ((pParentWidget = pParentWidget->parentWidget()) != 0)
 
713
                {
 
714
                    if (QTabWidget *pTabWidget = qobject_cast<QTabWidget*>(pParentWidget))
 
715
                    {
 
716
                        /* The tab contents widget is two steps down
 
717
                         * (QTabWidget -> QStackedWidget -> QWidget): */
 
718
                        QWidget *pTabPage = parents[parents.count() - 1];
 
719
                        if (pTabPage)
 
720
                            pTabPage = parents[parents.count() - 2];
 
721
                        if (pTabPage)
 
722
                            pTabWidget->setCurrentWidget(pTabPage);
 
723
                    }
 
724
                    parents.append(pParentWidget);
 
725
                }
 
726
                pWidget->setFocus();
 
727
            }
 
728
        }
 
729
    }
 
730
    /* First item as default: */
 
731
    else
 
732
        m_pSelector->selectById(MachineSettingsPageType_General);
 
733
}
 
734
 
 
735
UISettingsDialogMachine::~UISettingsDialogMachine()
 
736
{
 
737
    /* Delete serializer early if exists: */
 
738
    if (UISettingsSerializer::instance())
 
739
        delete UISettingsSerializer::instance();
 
740
}
 
741
 
 
742
void UISettingsDialogMachine::loadData()
 
743
{
 
744
    /* Check that session is NOT created: */
 
745
    if (!m_session.isNull())
 
746
        return;
 
747
 
 
748
    /* Call for base-class: */
 
749
    UISettingsDialog::loadData();
 
750
 
 
751
    /* Disconnect global VBox events from this dialog: */
 
752
    gVBoxEvents->disconnect(this);
 
753
 
 
754
    /* Prepare session: */
 
755
    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openExistingSession(m_strMachineId);
 
756
    /* Check that session was created: */
 
757
    if (m_session.isNull())
 
758
        return;
 
759
 
 
760
    /* Get machine from session: */
 
761
    m_machine = m_session.GetMachine();
 
762
    /* Get console from session: */
 
763
    m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
 
764
 
 
765
    /* Prepare machine data: */
 
766
    qRegisterMetaType<UISettingsDataMachine>();
 
767
    UISettingsDataMachine data(m_machine, m_console);
 
768
    /* Create machine settings loader,
 
769
     * it will load machine settings & delete itself in the appropriate time: */
 
770
    UISettingsSerializer *pMachineSettingsLoader = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Load);
 
771
    connect(pMachineSettingsLoader, SIGNAL(destroyed(QObject*)), this, SLOT(sltMarkLoaded()));
 
772
    connect(pMachineSettingsLoader, SIGNAL(sigNotifyAboutPagesProcessed()), this, SLOT(sltSetFirstRunFlag()));
 
773
    /* Set pages to be loaded: */
 
774
    pMachineSettingsLoader->setPageList(m_pSelector->settingPages());
 
775
    /* Ask to raise required page priority: */
 
776
    pMachineSettingsLoader->raisePriorityOfPage(m_pSelector->currentId());
 
777
    /* Start page loader: */
 
778
    pMachineSettingsLoader->start();
 
779
}
 
780
 
 
781
void UISettingsDialogMachine::saveData()
 
782
{
 
783
    /* Check that session is NOT created: */
 
784
    if (!m_session.isNull())
 
785
        return;
 
786
 
 
787
    /* Call for base-class: */
 
788
    UISettingsDialog::saveData();
 
789
 
 
790
    /* Disconnect global VBox events from this dialog: */
 
791
    gVBoxEvents->disconnect(this);
 
792
 
 
793
    /* Prepare session: */
 
794
    if (dialogType() == SettingsDialogType_Wrong)
 
795
        m_session = CSession();
 
796
    else if (dialogType() != SettingsDialogType_Offline)
 
797
        m_session = vboxGlobal().openExistingSession(m_strMachineId);
 
798
    else
 
799
        m_session = vboxGlobal().openSession(m_strMachineId);
 
800
    /* Check that session was created: */
 
801
    if (m_session.isNull())
 
802
        return;
 
803
 
 
804
    /* Get machine from session: */
 
805
    m_machine = m_session.GetMachine();
 
806
    /* Get console from session: */
 
807
    m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
 
808
 
 
809
    /* Prepare machine data: */
 
810
    qRegisterMetaType<UISettingsDataMachine>();
 
811
    UISettingsDataMachine data(m_machine, m_console);
 
812
    /* Create machine settings saver,
 
813
     * it will save machine settings & delete itself in the appropriate time: */
 
814
    UISettingsSerializer *pMachineSettingsSaver = new UISettingsSerializer(this, QVariant::fromValue(data), UISettingsSerializeDirection_Save);
 
815
    /* Set pages to be saved: */
 
816
    pMachineSettingsSaver->setPageList(m_pSelector->settingPages());
 
817
    /* Start saver: */
 
818
    pMachineSettingsSaver->start();
 
819
 
 
820
    /* Get updated machine: */
 
821
    m_machine = pMachineSettingsSaver->data().value<UISettingsDataMachine>().m_machine;
 
822
    /* If machine is ok => perform final operations: */
 
823
    if (m_machine.isOk())
 
824
    {
 
825
        /* Guest OS type & VT-x/AMD-V option correlation auto-fix: */
 
826
        UIMachineSettingsGeneral *pGeneralPage =
 
827
            qobject_cast<UIMachineSettingsGeneral*>(m_pSelector->idToPage(MachineSettingsPageType_General));
 
828
        UIMachineSettingsSystem *pSystemPage =
 
829
            qobject_cast<UIMachineSettingsSystem*>(m_pSelector->idToPage(MachineSettingsPageType_System));
 
830
        if (pGeneralPage && pSystemPage &&
 
831
            pGeneralPage->is64BitOSTypeSelected() && !pSystemPage->isHWVirtExEnabled())
 
832
            m_machine.SetHWVirtExProperty(KHWVirtExPropertyType_Enabled, true);
 
833
 
 
834
#ifdef VBOX_WITH_VIDEOHWACCEL
 
835
        /* Disable 2D Video Acceleration for non-Windows guests: */
 
836
        if (pGeneralPage && !pGeneralPage->isWindowsOSTypeSelected())
 
837
        {
 
838
            UIMachineSettingsDisplay *pDisplayPage =
 
839
                qobject_cast<UIMachineSettingsDisplay*>(m_pSelector->idToPage(MachineSettingsPageType_Display));
 
840
            if (pDisplayPage && pDisplayPage->isAcceleration2DVideoSelected())
 
841
                m_machine.SetAccelerate2DVideoEnabled(false);
 
842
        }
 
843
#endif /* VBOX_WITH_VIDEOHWACCEL */
 
844
 
 
845
        /* Enable OHCI controller if HID is enabled: */
 
846
        if (pSystemPage && pSystemPage->isHIDEnabled())
 
847
        {
 
848
            ULONG cOhciCtls = m_machine.GetUSBControllerCountByType(KUSBControllerType_OHCI);
 
849
            if (!cOhciCtls)
 
850
                m_machine.AddUSBController("OHCI", KUSBControllerType_OHCI);
 
851
        }
 
852
 
 
853
        /* Clear the "GUI_FirstRun" extra data key in case if
 
854
         * the boot order or disk configuration were changed: */
 
855
        if (m_fResetFirstRunFlag)
 
856
            m_machine.SetExtraData(GUI_FirstRun, QString::null);
 
857
 
 
858
        /* Save settings finally: */
 
859
        m_machine.SaveSettings();
 
860
    }
 
861
 
 
862
    /* If machine is NOT ok => show the error message: */
 
863
    if (!m_machine.isOk())
 
864
        msgCenter().cannotSaveMachineSettings(m_machine, this);
 
865
 
 
866
    /* Mark page processed: */
 
867
    sltMarkSaved();
 
868
}
 
869
 
 
870
void UISettingsDialogMachine::retranslateUi()
 
871
{
 
872
    /* We have to make sure that the Network, Serial & Parallel pages are retranslated
 
873
     * before they are revalidated. Cause: They do string comparing within
 
874
     * vboxGlobal which is retranslated at that point already: */
 
875
    QEvent event(QEvent::LanguageChange);
 
876
    if (QWidget *pPage = m_pSelector->idToPage(MachineSettingsPageType_Network))
 
877
        qApp->sendEvent(pPage, &event);
 
878
    if (QWidget *pPage = m_pSelector->idToPage(MachineSettingsPageType_Serial))
 
879
        qApp->sendEvent(pPage, &event);
 
880
    if (QWidget *pPage = m_pSelector->idToPage(MachineSettingsPageType_Parallel))
 
881
        qApp->sendEvent(pPage, &event);
 
882
 
 
883
    /* General page: */
 
884
    m_pSelector->setItemText(MachineSettingsPageType_General, tr("General"));
 
885
 
 
886
    /* System page: */
 
887
    m_pSelector->setItemText(MachineSettingsPageType_System, tr("System"));
 
888
 
 
889
    /* Display page: */
 
890
    m_pSelector->setItemText(MachineSettingsPageType_Display, tr("Display"));
 
891
 
 
892
    /* Storage page: */
 
893
    m_pSelector->setItemText(MachineSettingsPageType_Storage, tr("Storage"));
 
894
 
 
895
    /* Audio page: */
 
896
    m_pSelector->setItemText(MachineSettingsPageType_Audio, tr("Audio"));
 
897
 
 
898
    /* Network page: */
 
899
    m_pSelector->setItemText(MachineSettingsPageType_Network, tr("Network"));
 
900
 
 
901
    /* Ports page: */
 
902
    m_pSelector->setItemText(MachineSettingsPageType_Ports, tr("Ports"));
 
903
 
 
904
    /* Serial page: */
 
905
    m_pSelector->setItemText(MachineSettingsPageType_Serial, tr("Serial Ports"));
 
906
 
 
907
    /* Parallel page: */
 
908
    m_pSelector->setItemText(MachineSettingsPageType_Parallel, tr("Parallel Ports"));
 
909
 
 
910
    /* USB page: */
 
911
    m_pSelector->setItemText(MachineSettingsPageType_USB, tr("USB"));
 
912
 
 
913
    /* SFolders page: */
 
914
    m_pSelector->setItemText(MachineSettingsPageType_SF, tr("Shared Folders"));
 
915
 
 
916
    /* Polish the selector: */
 
917
    m_pSelector->polish();
 
918
 
 
919
    /* Base-class UI translation: */
 
920
    UISettingsDialog::retranslateUi();
 
921
 
 
922
    /* Set dialog's name: */
 
923
    setWindowTitle(title());
 
924
}
 
925
 
 
926
QString UISettingsDialogMachine::title() const
 
927
{
 
928
    QString strDialogTitle;
 
929
    /* Get corresponding machine (required to compose dialog title): */
 
930
    const CMachine &machine = vboxGlobal().virtualBox().FindMachine(m_strMachineId);
 
931
    if (!machine.isNull())
 
932
        strDialogTitle = tr("%1 - %2").arg(machine.GetName()).arg(titleExtension());
 
933
    return strDialogTitle;
 
934
}
 
935
 
 
936
void UISettingsDialogMachine::recorrelate(UISettingsPage *pSettingsPage)
 
937
{
 
938
    switch (pSettingsPage->id())
 
939
    {
 
940
        /* General page correlations: */
 
941
        case MachineSettingsPageType_General:
 
942
        {
 
943
            /* Make changes on 'general' page influent 'display' page: */
 
944
            UIMachineSettingsGeneral *pGeneralPage = qobject_cast<UIMachineSettingsGeneral*>(pSettingsPage);
 
945
            UIMachineSettingsDisplay *pDisplayPage = qobject_cast<UIMachineSettingsDisplay*>(m_pSelector->idToPage(MachineSettingsPageType_Display));
 
946
            if (pGeneralPage && pDisplayPage)
 
947
                pDisplayPage->setGuestOSType(pGeneralPage->guestOSType());
 
948
            break;
 
949
        }
 
950
        /* System page correlations: */
 
951
        case MachineSettingsPageType_System:
 
952
        {
 
953
            /* Make changes on 'system' page influent 'general' and 'storage' page: */
 
954
            UIMachineSettingsSystem *pSystemPage = qobject_cast<UIMachineSettingsSystem*>(pSettingsPage);
 
955
            UIMachineSettingsGeneral *pGeneralPage = qobject_cast<UIMachineSettingsGeneral*>(m_pSelector->idToPage(MachineSettingsPageType_General));
 
956
            UIMachineSettingsStorage *pStoragePage = qobject_cast<UIMachineSettingsStorage*>(m_pSelector->idToPage(MachineSettingsPageType_Storage));
 
957
            if (pSystemPage)
 
958
            {
 
959
                if (pGeneralPage)
 
960
                    pGeneralPage->setHWVirtExEnabled(pSystemPage->isHWVirtExEnabled());
 
961
                if (pStoragePage)
 
962
                    pStoragePage->setChipsetType(pSystemPage->chipsetType());
 
963
            }
 
964
            break;
 
965
        }
 
966
        /* USB page correlations: */
 
967
        case MachineSettingsPageType_USB:
 
968
        {
 
969
            /* Make changes on 'usb' page influent 'system' page: */
 
970
            UIMachineSettingsUSB *pUsbPage = qobject_cast<UIMachineSettingsUSB*>(pSettingsPage);
 
971
            UIMachineSettingsSystem *pSystemPage = qobject_cast<UIMachineSettingsSystem*>(m_pSelector->idToPage(MachineSettingsPageType_System));
 
972
            if (pUsbPage && pSystemPage)
 
973
                pSystemPage->setOHCIEnabled(pUsbPage->isOHCIEnabled());
 
974
            break;
 
975
        }
 
976
        default:
 
977
            break;
 
978
    }
 
979
}
 
980
 
 
981
void UISettingsDialogMachine::sltMarkLoaded()
 
982
{
 
983
    /* Call for base-class: */
 
984
    UISettingsDialog::sltMarkLoaded();
 
985
 
 
986
    /* Unlock the session if exists: */
 
987
    if (!m_session.isNull())
 
988
    {
 
989
        m_session.UnlockMachine();
 
990
        m_session = CSession();
 
991
        m_machine = CMachine();
 
992
        m_console = CConsole();
 
993
    }
 
994
 
 
995
    /* Make sure settings window will be updated on machine state/data changes: */
 
996
    connect(gVBoxEvents, SIGNAL(sigSessionStateChange(QString, KSessionState)),
 
997
            this, SLOT(sltSessionStateChanged(QString, KSessionState)));
 
998
    connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QString, KMachineState)),
 
999
            this, SLOT(sltMachineStateChanged(QString, KMachineState)));
 
1000
    connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)),
 
1001
            this, SLOT(sltMachineDataChanged(QString)));
 
1002
}
 
1003
 
 
1004
void UISettingsDialogMachine::sltMarkSaved()
 
1005
{
 
1006
    /* Call for base-class: */
 
1007
    UISettingsDialog::sltMarkSaved();
 
1008
 
 
1009
    /* Unlock the session if exists: */
 
1010
    if (!m_session.isNull())
 
1011
    {
 
1012
        m_session.UnlockMachine();
 
1013
        m_session = CSession();
 
1014
        m_machine = CMachine();
 
1015
        m_console = CConsole();
 
1016
    }
 
1017
}
 
1018
 
 
1019
void UISettingsDialogMachine::sltSessionStateChanged(QString strMachineId, KSessionState sessionState)
 
1020
{
 
1021
    /* Ignore if thats NOT our VM: */
 
1022
    if (strMachineId != m_strMachineId)
 
1023
        return;
 
1024
 
 
1025
    /* Ignore if state was NOT actually changed: */
 
1026
    if (m_sessionState == sessionState)
 
1027
        return;
 
1028
 
 
1029
    /* Update current session state: */
 
1030
    m_sessionState = sessionState;
 
1031
 
 
1032
    /* Update dialog-type if necessary: */
 
1033
    updateDialogType();
 
1034
}
 
1035
 
 
1036
void UISettingsDialogMachine::sltMachineStateChanged(QString strMachineId, KMachineState machineState)
 
1037
{
 
1038
    /* Ignore if thats NOT our VM: */
 
1039
    if (strMachineId != m_strMachineId)
 
1040
        return;
 
1041
 
 
1042
    /* Ignore if state was NOT actually changed: */
 
1043
    if (m_machineState == machineState)
 
1044
        return;
 
1045
 
 
1046
    /* Update current machine state: */
 
1047
    m_machineState = machineState;
 
1048
 
 
1049
    /* Update dialog-type if necessary: */
 
1050
    updateDialogType();
 
1051
}
 
1052
 
 
1053
void UISettingsDialogMachine::sltMachineDataChanged(QString strMachineId)
 
1054
{
 
1055
    /* Ignore if thats NOT our VM: */
 
1056
    if (strMachineId != m_strMachineId)
 
1057
        return;
 
1058
 
 
1059
    /* Check if user had changed something and warn him about he will loose settings on reloading: */
 
1060
    if (isSettingsChanged() && !msgCenter().confirmSettingsReloading(this))
 
1061
        return;
 
1062
 
 
1063
    /* Reload data: */
 
1064
    loadData();
 
1065
}
 
1066
 
 
1067
void UISettingsDialogMachine::sltCategoryChanged(int cId)
 
1068
{
 
1069
    if (UISettingsSerializer::instance())
 
1070
        UISettingsSerializer::instance()->raisePriorityOfPage(cId);
 
1071
 
 
1072
    UISettingsDialog::sltCategoryChanged(cId);
 
1073
}
 
1074
 
 
1075
void UISettingsDialogMachine::sltAllowResetFirstRunFlag()
 
1076
{
 
1077
    m_fAllowResetFirstRunFlag = true;
 
1078
}
 
1079
 
 
1080
void UISettingsDialogMachine::sltSetFirstRunFlag()
 
1081
{
 
1082
    m_fResetFirstRunFlag = false;
 
1083
}
 
1084
 
 
1085
void UISettingsDialogMachine::sltResetFirstRunFlag()
 
1086
{
 
1087
    if (m_fAllowResetFirstRunFlag)
 
1088
        m_fResetFirstRunFlag = true;
 
1089
}
 
1090
 
 
1091
bool UISettingsDialogMachine::isPageAvailable(int iPageId)
 
1092
{
 
1093
    if (m_machine.isNull())
 
1094
        return false;
 
1095
 
 
1096
    switch (iPageId)
 
1097
    {
 
1098
        case MachineSettingsPageType_Serial:
 
1099
        {
 
1100
            /* Depends on ports availability: */
 
1101
            if (!isPageAvailable(MachineSettingsPageType_Ports))
 
1102
                return false;
 
1103
            break;
 
1104
        }
 
1105
        case MachineSettingsPageType_Parallel:
 
1106
        {
 
1107
            /* Depends on ports availability: */
 
1108
            if (!isPageAvailable(MachineSettingsPageType_Ports))
 
1109
                return false;
 
1110
            /* But for now this page is always disabled: */
 
1111
            return false;
 
1112
        }
 
1113
        case MachineSettingsPageType_USB:
 
1114
        {
 
1115
            /* Depends on ports availability: */
 
1116
            if (!isPageAvailable(MachineSettingsPageType_Ports))
 
1117
                return false;
 
1118
            /* Check if USB is implemented: */
 
1119
            if (!m_machine.GetUSBProxyAvailable())
 
1120
                return false;
 
1121
            /* Get the USB controller object: */
 
1122
            CUSBControllerVector controllerColl = m_machine.GetUSBControllers();
 
1123
            /* Show the machine error message if any: */
 
1124
            if (   !m_machine.isReallyOk()
 
1125
                && controllerColl.size() > 0
 
1126
                && m_machine.GetUSBControllerCountByType(KUSBControllerType_OHCI))
 
1127
                msgCenter().warnAboutUnaccessibleUSB(m_machine, parentWidget());
 
1128
            break;
 
1129
        }
 
1130
        default:
 
1131
            break;
 
1132
    }
 
1133
    return true;
 
1134
}
 
1135
 
 
1136
bool UISettingsDialogMachine::isSettingsChanged()
 
1137
{
 
1138
    bool fIsSettingsChanged = false;
 
1139
    foreach (UISettingsPage *pPage, m_pSelector->settingPages())
 
1140
    {
 
1141
        pPage->putToCache();
 
1142
        if (!fIsSettingsChanged && pPage->changed())
 
1143
            fIsSettingsChanged = true;
 
1144
    }
 
1145
    return fIsSettingsChanged;
 
1146
}
 
1147
 
 
1148
void UISettingsDialogMachine::updateDialogType()
 
1149
{
 
1150
    /* Get new dialog type: */
 
1151
    SettingsDialogType newDialogType = determineSettingsDialogType(m_sessionState, m_machineState);
 
1152
 
 
1153
    /* Ignore if dialog type was NOT actually changed: */
 
1154
    if (dialogType() == newDialogType)
 
1155
        return;
 
1156
 
 
1157
    /* Should we show a warning about leaving 'offline' state? */
 
1158
    bool fShouldWe = dialogType() == SettingsDialogType_Offline;
 
1159
 
 
1160
    /* Update current dialog type: */
 
1161
    setDialogType(newDialogType);
 
1162
 
 
1163
    /* Show a warning about leaving 'offline' state if we should: */
 
1164
    if (isSettingsChanged() && fShouldWe)
 
1165
        msgCenter().warnAboutStateChange(this);
 
1166
}
 
1167
 
 
1168
# include "UISettingsDialogSpecific.moc"
 
1169