/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. #include "window.h"
  19. #include "adddialog.h"
  20. #include "removedialog.h"
  21. #include "view.h"
  22. #include <QTimer>
  23. #include <KAction>
  24. #include <KActionCollection>
  25. #include <KActionMenu>
  26. #include <KApplication>
  27. #include <KLocalizedString>
  28. #include <KStatusBar>
  29. Kandas::Client::MainWindow::MainWindow()
  30. : m_addDialogAct(0)
  31. , m_removeDialogAct(0)
  32. , m_addDialog(0)
  33. , m_removeDialog(0)
  34. , m_view(new Kandas::Client::View(this))
  35. {
  36. //early GUI initialisation
  37. setupActions();
  38. setAutoSaveSettings();
  39. //central widget
  40. setCentralWidget(m_view);
  41. connect(m_view, SIGNAL(initializationComplete(const QString &)), this, SLOT(initializationComplete(const QString &)));
  42. //late GUI initialisation
  43. setupGUI();
  44. statusBar()->hide();
  45. setMinimumSize(QSize(300, 300));
  46. setWindowIcon(KIcon("folder-remote"));
  47. QTimer::singleShot(0, this, SLOT(setupDialogs()));
  48. }
  49. Kandas::Client::MainWindow::~MainWindow()
  50. {
  51. delete m_addDialog;
  52. delete m_removeDialog;
  53. }
  54. void Kandas::Client::MainWindow::setupActions()
  55. {
  56. m_addDialogAct = new KAction(KIcon("list-add"), i18n("Register drive..."), actionCollection());
  57. actionCollection()->addAction("kandas_device_add", m_addDialogAct);
  58. m_removeDialogAct = new KAction(KIcon("list-remove"), i18n("Remove drive..."), actionCollection());
  59. actionCollection()->addAction("kandas_device_remove", m_removeDialogAct);
  60. }
  61. void Kandas::Client::MainWindow::setupDialogs()
  62. {
  63. if (!m_addDialog)
  64. {
  65. m_addDialog = new Kandas::Client::AddDialog(m_view->manager());
  66. connect(m_addDialogAct, SIGNAL(triggered()), m_addDialog, SLOT(showDialog()));
  67. }
  68. if (!m_removeDialog)
  69. {
  70. m_removeDialog = new Kandas::Client::RemoveDialog(m_view->manager());
  71. connect(m_removeDialogAct, SIGNAL(triggered()), m_removeDialog, SLOT(showDialog()));
  72. }
  73. }
  74. void Kandas::Client::MainWindow::initializationComplete(const QString &daemonVersion)
  75. {
  76. bool hasDaemon = !daemonVersion.isEmpty();
  77. m_addDialogAct->setEnabled(hasDaemon);
  78. m_removeDialogAct->setEnabled(hasDaemon);
  79. show();
  80. }
  81. #include "window.moc"