mainwindow.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2008  Tim Fechtner < urwald at users dot sourceforge dot net >
00003 
00004     This program is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU General Public License as
00006     published by the Free Software Foundation; either version 2 of
00007     the License or (at your option) version 3 or any later version
00008     accepted by the membership of KDE e.V. (or its successor approved
00009     by the membership of KDE e.V.), which shall act as a proxy
00010     defined in Section 14 of version 3 of the license.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "mainwindow.h"
00022 
00023 #include "settings_general_dialog.h"
00024 #include "stationdirectorytree.h"
00025 #include <QDockWidget>
00026 #include <KApplication>
00027 #include <KAction>
00028 #include <KLocale>
00029 #include <KActionCollection>
00030 #include <KTipDialog>
00031 #include <KStatusBar>
00032 #include <KStandardDirs>
00033 
00034 MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent)
00035 {
00036   //initialise central widget
00037   m_streamlistwidget = new stationlistWidget(this);
00038   setCentralWidget(m_streamlistwidget);
00039 
00040   //setup actions
00041   KStandardAction::preferences(this, SLOT(display_global_settings_dialog()),
00042                                 actionCollection());
00043 
00044   KStandardAction::quit(kapp, SLOT(quit()), actionCollection());
00045 
00046   KAction * newStreamAction = new KAction(this);
00047   newStreamAction->setText(i18nc("@action", "&New stream"));
00048   newStreamAction->setIcon(KIcon("document-new"));
00049   newStreamAction->setShortcut(QKeySequence::New);
00050   connect(newStreamAction, SIGNAL(triggered(bool)),
00051            m_streamlistwidget, SLOT(addNewStation()));
00052   actionCollection()->addAction("newStream", newStreamAction);
00053   m_streamlistwidget->contextMenu.addAction(newStreamAction);
00054 
00055   KAction * deleteStreamAction = new KAction(this);
00056   deleteStreamAction->setText(i18nc("@action", "&Delete stream"));
00057   deleteStreamAction->setIcon(KIcon("edit-delete"));
00058   deleteStreamAction->setShortcut(Qt::SHIFT + Qt::Key_Delete);
00059   deleteStreamAction->setDisabled(true);
00060   connect(deleteStreamAction, SIGNAL(triggered(bool)),
00061            m_streamlistwidget, SLOT(deleteStation()));
00062   connect(m_streamlistwidget, SIGNAL(noneSelected(bool)),
00063            deleteStreamAction, SLOT(setDisabled(bool)));
00064   connect(m_streamlistwidget, SIGNAL(oneSelected(bool)),
00065            deleteStreamAction, SLOT(setEnabled(bool)));
00066   connect(m_streamlistwidget, SIGNAL(multipleSelected(bool)),
00067            deleteStreamAction, SLOT(setEnabled(bool)));
00068   actionCollection()->addAction("deleteStream", deleteStreamAction);
00069   m_streamlistwidget->contextMenu.addAction(deleteStreamAction);
00070 
00071   KAction * selectAllAction = KStandardAction::selectAll(m_streamlistwidget, SLOT(selectAll()),
00072                                                           actionCollection());
00073   m_streamlistwidget->contextMenu.addAction(selectAllAction);
00074 
00075   KAction * recordAction = new KAction(this);
00076   recordAction->setText(i18nc("@action", "&Record"));
00077   recordAction->setIcon(KIcon("media-record"));
00078   // TODO: use a appropriate value and accept multimedia keys also
00079   recordAction->setShortcut(Qt::CTRL + Qt::Key_R);
00080   recordAction->setDisabled(true);
00081   connect(recordAction, SIGNAL(triggered(bool)),
00082            m_streamlistwidget, SLOT(record()));
00083   connect(m_streamlistwidget, SIGNAL(noneSelected(bool)),
00084            recordAction, SLOT(setDisabled(bool)));
00085   // TODO: enable only when the stream is really stoped...
00086   connect(m_streamlistwidget, SIGNAL(oneSelected(bool)),
00087            recordAction, SLOT(setEnabled(bool)));
00088   // TODO: enable only when there are also streams that are really stoped...
00089   connect(m_streamlistwidget, SIGNAL(multipleSelected(bool)),
00090            recordAction, SLOT(setEnabled(bool)));
00091   actionCollection()->addAction("record", recordAction);
00092   m_streamlistwidget->contextMenu.addAction(recordAction);
00093 
00094   KAction * stopRecordAction = new KAction(this);
00095   stopRecordAction->setText(i18nc("@action", "&Stop"));
00096   stopRecordAction->setIcon(KIcon("media-playback-stop"));
00097   QList<QKeySequence> stopRecordAction_tempShortcutList;
00098   stopRecordAction_tempShortcutList.append(Qt::Key_S);
00099   stopRecordAction_tempShortcutList.append(Qt::CTRL + Qt::Key_S);
00100   stopRecordAction_tempShortcutList.append(Qt::META + Qt::Key_V);
00101   // TODO: use a appropriate value and accept multimedia keys also
00102   stopRecordAction->setShortcuts(stopRecordAction_tempShortcutList);
00103   stopRecordAction->setDisabled(true);
00104   connect(stopRecordAction, SIGNAL(triggered(bool)),
00105            m_streamlistwidget, SLOT(stopRecord()));
00106   connect(m_streamlistwidget, SIGNAL(noneSelected(bool)),
00107            stopRecordAction, SLOT(setDisabled(bool)));
00108   // TODO: enable only when the streams are really running:
00109   connect(m_streamlistwidget, SIGNAL(oneSelected(bool)),
00110            stopRecordAction, SLOT(setEnabled(bool)));
00111   // TODO: enable only when the streams are really running:
00112   connect(m_streamlistwidget, SIGNAL(multipleSelected(bool)),
00113            stopRecordAction, SLOT(setEnabled(bool)));
00114   actionCollection()->addAction("stopRecord", stopRecordAction);
00115   m_streamlistwidget->contextMenu.addAction(stopRecordAction);
00116 
00117   KAction * streamSettingsAction = new KAction(this);
00118   streamSettingsAction->setText(i18nc("@action properties of a stream)", "&Properties"));
00119   //stopRecordAction->setIcon(KIcon("media-playback-stop")); // TODO: use a appropriate value
00120   streamSettingsAction->setShortcut(Qt::ALT + Qt::Key_Return);
00121   // TODO: use a appropriate value and accept multimedia keys also
00122   streamSettingsAction->setDisabled(true);
00123   connect(streamSettingsAction, SIGNAL(triggered(bool)),
00124            m_streamlistwidget, SLOT(displayStreamSettings()));
00125   connect(m_streamlistwidget, SIGNAL(noneSelected(bool)),
00126            streamSettingsAction, SLOT(setDisabled(bool)));
00127   connect(m_streamlistwidget, SIGNAL(oneSelected(bool)),
00128            streamSettingsAction, SLOT(setEnabled(bool)));
00129   // TODO: maybe make this possible later:
00130   connect(m_streamlistwidget, SIGNAL(multipleSelected(bool)),
00131            streamSettingsAction, SLOT(setDisabled(bool)));
00132   actionCollection()->addAction("streamSettings", streamSettingsAction);
00133   m_streamlistwidget->contextMenu.addAction(streamSettingsAction);
00134 
00135   KStandardAction::tipOfDay(this, SLOT(displayTipOfDay()), actionCollection());
00136 
00137   //setup GUI
00138   setupGUI();
00139 
00140   statusBar()->insertPermanentItem(QString(), 0);
00141   statusBar()->insertPermanentItem(QString(), 1);
00142   connect(m_streamlistwidget->stationlistmodel(),
00143            SIGNAL(bandwidthChanged()),
00144            this,
00145            SLOT(actualize_bandwidth_in_statusBar()));
00146   connect(m_streamlistwidget->stationlistmodel(),
00147            SIGNAL(numberOfActiveStreamsChanged()),
00148            this,
00149            SLOT(actualize_numberOfActiveStreams_in_statusBar()));
00150   actualize_bandwidth_in_statusBar();  // initialization
00151   actualize_numberOfActiveStreams_in_statusBar();  // initialization
00152 
00153   QDockWidget *m_streamDirectory = new QDockWidget(
00154     i18nc("@title:window Dock name of the directory of radio stations",
00155           "Shoutcast radiostation directory"),
00156     this);
00157   m_streamDirectory->setObjectName("theRadiostationDirectory");  // to avoid a warning on stdout
00158   m_streamDirectory->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea |
00159     Qt::BottomDockWidgetArea);
00160   stationDirectoryTree *mainwidget_of_dock = new stationDirectoryTree(
00161     m_streamDirectory,
00162     KStandardDirs::locate("appdata", "action-favorite-genres-amarok.svgz"));
00163   m_streamDirectory->setWidget(mainwidget_of_dock);
00164   addDockWidget(Qt::LeftDockWidgetArea, m_streamDirectory);
00165 
00166   KTipDialog::showTip(this, "kradioripper/tips");
00167 }
00168 
00169 MainWindow::~MainWindow()
00170 {
00171 }
00172 
00173 void MainWindow::actualize_numberOfActiveStreams_in_statusBar()
00174 {
00175   statusBar()->changeItem(
00176     i18ncp("@info:status",
00177             "Recording %1 stream.",
00178             "Recording %1 streams.",
00179             m_streamlistwidget->stationlistmodel()->numberOfActiveStreams()),
00180     0);
00181 }
00182 
00183 void MainWindow::actualize_bandwidth_in_statusBar()
00184 {
00185   statusBar()->changeItem(
00186     i18ncp("@info:status The unit is kbit (=1000 bit) instead of Kibit (=1024 bit). "
00187               "See http://en.wikipedia.org/wiki/Binary_prefix for details.",
00188             "%1 kbit/s",
00189             "%1 kbit/s",
00190             m_streamlistwidget->stationlistmodel()->bandwidth()),
00191     1);
00192 }
00193 
00194 bool MainWindow::queryClose()
00195 {
00196   return m_streamlistwidget->queryClose();
00197 }
00198 
00199 void MainWindow::saveProperties(KConfigGroup & m_configGroup)
00200 {
00201   m_streamlistwidget->saveProperties(m_configGroup);
00202 }
00203 
00204 void MainWindow::readProperties(const KConfigGroup & m_configGroup)
00205 {
00206   m_streamlistwidget->readProperties(m_configGroup);
00207 }
00208 
00209 void MainWindow::display_global_settings_dialog()
00210 {
00211   // if the dialog object yet exists, we can display it directly and return.
00212   if (KConfigDialog::showDialog("settings_general_dialog")) {
00213     return;
00214   };
00215 
00216   // else we have to construct and configure it before displaying it and return
00217   settings_general_dialog * dialog = new settings_general_dialog(this,
00218                                                                   "settings_general_dialog");
00219   dialog->show();
00220 }
00221 
00222 void MainWindow::displayTipOfDay()
00223 {
00224   KTipDialog::showTip(this, "kradioripper/tips", true);
00225 }

Generated on Sat May 2 10:43:44 2009 for kradioripper by  doxygen 1.5.6