PageRenderTime 28ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/kandas-client/window.cpp

http://kandas.googlecode.com/
C++ | 89 lines | 61 code | 8 blank | 20 comment | 2 complexity | b3754665b8036004b5663f1dd45caa14 MD5 | raw file
 1/***************************************************************************
 2 *   Copyright 2008-2009 Stefan Majewsky <majewsky@gmx.net>
 3 *
 4 *   This program is free software; you can redistribute it and/or
 5 *   modify it under the terms of the GNU General Public
 6 *   License as published by the Free Software Foundation; either
 7 *   version 2 of the License, or (at your option) any later version.
 8 *
 9 *   This program is distributed in the hope that it will be useful,
10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *   GNU General Public License for more details.
13 *
14 *   You should have received a copy of the GNU General Public License
15 *   along with this program; if not, write to the Free Software
16 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 ***************************************************************************/
18
19#include "window.h"
20#include "adddialog.h"
21#include "removedialog.h"
22#include "view.h"
23
24#include <QTimer>
25#include <KAction>
26#include <KActionCollection>
27#include <KActionMenu>
28#include <KApplication>
29#include <KLocalizedString>
30#include <KStatusBar>
31
32Kandas::Client::MainWindow::MainWindow()
33    : m_addDialogAct(0)
34    , m_removeDialogAct(0)
35    , m_addDialog(0)
36    , m_removeDialog(0)
37    , m_view(new Kandas::Client::View(this))
38{
39    //early GUI initialisation
40    setupActions();
41    setAutoSaveSettings();
42    //central widget
43    setCentralWidget(m_view);
44    connect(m_view, SIGNAL(initializationComplete(const QString &)), this, SLOT(initializationComplete(const QString &)));
45    //late GUI initialisation
46    setupGUI();
47    statusBar()->hide();
48    setMinimumSize(QSize(300, 300));
49    setWindowIcon(KIcon("folder-remote"));
50    QTimer::singleShot(0, this, SLOT(setupDialogs()));
51}
52
53Kandas::Client::MainWindow::~MainWindow()
54{
55    delete m_addDialog;
56    delete m_removeDialog;
57}
58
59void Kandas::Client::MainWindow::setupActions()
60{
61    m_addDialogAct = new KAction(KIcon("list-add"), i18n("Register drive..."), actionCollection());
62    actionCollection()->addAction("kandas_device_add", m_addDialogAct);
63    m_removeDialogAct = new KAction(KIcon("list-remove"), i18n("Remove drive..."), actionCollection());
64    actionCollection()->addAction("kandas_device_remove", m_removeDialogAct);
65}
66
67void Kandas::Client::MainWindow::setupDialogs()
68{
69    if (!m_addDialog)
70    {
71        m_addDialog = new Kandas::Client::AddDialog(m_view->manager());
72        connect(m_addDialogAct, SIGNAL(triggered()), m_addDialog, SLOT(showDialog()));
73    }
74    if (!m_removeDialog)
75    {
76        m_removeDialog = new Kandas::Client::RemoveDialog(m_view->manager());
77        connect(m_removeDialogAct, SIGNAL(triggered()), m_removeDialog, SLOT(showDialog()));
78    }
79}
80
81void Kandas::Client::MainWindow::initializationComplete(const QString &daemonVersion)
82{
83    bool hasDaemon = !daemonVersion.isEmpty();
84    m_addDialogAct->setEnabled(hasDaemon);
85    m_removeDialogAct->setEnabled(hasDaemon);
86    show();
87}
88
89#include "window.moc"