00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "mainwindow.h"
00022
00023 #include <QList>
00024 #include <QTreeView>
00025 #include <KApplication>
00026 #include <KActionCollection>
00027 #include <KLocale>
00028 #include <KMessageBox>
00029 #include <KTipDialog>
00030 #include <KStatusBar>
00031 #include <KStandardDirs>
00032 #include <KWindowSystem>
00033 #include "importkradiorippersettings.h"
00034 #include "settings_general.h"
00035 #include "settings_general_dialog.h"
00036
00037 MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent)
00038 {
00039
00040 m_streamlistwidget = new stationlistWidget(actionCollection(), this);
00041 setCentralWidget(m_streamlistwidget);
00042
00043
00044 setupStreamDirectory();
00045
00046 setupActions();
00047 setupGUI();
00048
00049
00050 QAction *helpContentsAction = actionCollection()->action("help_contents");
00051 if (!(helpContentsAction == 0)) {
00052 helpContentsAction->setVisible(false);
00053 };
00054 connect(KApplication::kApplication(),
00055 SIGNAL(aboutToQuit()),
00056 this,
00057 SLOT(prepareForExitingApp()));
00058 setupSystrayAndStatusbar();
00059 importKradioripperSettings::askForImport(true);
00060 KTipDialog::showTip(this, "kstreamripper/tips");
00061 }
00062
00063 MainWindow::~MainWindow()
00064 {
00065
00066 }
00067
00068 void MainWindow::closeEvent(QCloseEvent *event)
00069 {
00070 if (QSystemTrayIcon::isSystemTrayAvailable() && systray.isVisible() && !kapp->sessionSaving()) {
00071 KMessageBox::information(
00072 this,
00073 i18nc("@info",
00074 "Closing the main window will keep KStreamRipper running in the "
00075 "system tray. Use 'Quit' from the 'File' menu to quit the application."),
00076 i18nc("@title:window", "Docking in System Tray"),
00077 "hideOnCloseInfo");
00078 toggleVisibility();
00079 event->ignore();
00080 } else {
00081 event->accept();
00082 };
00083 }
00084
00085 void MainWindow::setupSystrayAndStatusbar()
00086 {
00087 systray.setIcon(QApplication::windowIcon());
00088 if (KDE::versionMajor() >= 4 && KDE::versionMinor() >= 4) {
00089 systray.show();
00090 } else {
00091 systray.hide();
00092 };
00093 connect(&systray,
00094 SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
00095 this,
00096 SLOT(toggleVisibility(const QSystemTrayIcon::ActivationReason)));
00097 statusBar()->insertPermanentItem(QString(), 0);
00098 statusBar()->insertPermanentItem(QString(), 1);
00099 connect(m_streamlistwidget->stationlistmodel(),
00100 SIGNAL(bandwidthChanged()),
00101 this,
00102 SLOT(actualize_systray_and_statusbar()));
00103 connect(m_streamlistwidget->stationlistmodel(),
00104 SIGNAL(numberOfActiveStreamsChanged()),
00105 this,
00106 SLOT(actualize_systray_and_statusbar()));
00107 actualize_systray_and_statusbar();
00108 }
00109
00110 void MainWindow::setupStreamDirectory()
00111 {
00112 m_streamDirectory = new streamdirectoryDockwidget(this);
00113 addDockWidget(Qt::LeftDockWidgetArea, m_streamDirectory);
00114 }
00115
00116 void MainWindow::setVisible(bool visible)
00117 {
00118
00119 KXmlGuiWindow::setVisible(visible);
00120 showStreamdirectory(showStreamdirectoryAction->isChecked());
00121 }
00122
00123 void MainWindow::toggleVisibility(const QSystemTrayIcon::ActivationReason reason)
00124 {
00125 if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick) {
00126 if (KWindowSystem::windowInfo(winId(), NET::WMDesktop).
00127 isOnDesktop(KWindowSystem::currentDesktop())) {
00128 if (isMinimized()) {
00129 KWindowSystem::unminimizeWindow(winId());
00130 } else {
00131 setVisible(!isVisible());
00132 };
00133 } else {
00134 KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
00135 show();
00136 KWindowSystem::unminimizeWindow(winId());
00137 KWindowSystem::activateWindow(winId());
00138 };
00139 };
00140 }
00141
00142 void MainWindow::actualize_systray_and_statusbar()
00143 {
00144 statusBar()->changeItem(
00145 i18ncp("@info:status",
00146 "Recording %1 stream.",
00147 "Recording %1 streams.",
00148 m_streamlistwidget->stationlistmodel()->numberOfActiveStreams()),
00149 0);
00150 statusBar()->changeItem(
00151 i18ncp("@info:status The unit is kbit (=1000 bit) instead of Kibit (=1024 bit). "
00152 "See http://en.wikipedia.org/wiki/Binary_prefix for details.",
00153 "%1 kbit/s",
00154 "%1 kbit/s",
00155 m_streamlistwidget->stationlistmodel()->bandwidth()),
00156 1);
00157 systray.setToolTip(statusBar()->itemText(0) + ' ' + statusBar()->itemText(1));
00158 }
00159
00160 bool MainWindow::queryClose()
00161 {
00162 return m_streamlistwidget->queryClose();
00163 }
00164
00165 void MainWindow::saveProperties(KConfigGroup & m_configGroup)
00166 {
00167 m_configGroup.writeEntry("isHiddenInSystray", !isVisible());
00168
00169 m_streamlistwidget->saveProperties(m_configGroup);
00170 }
00171
00172 void MainWindow::readProperties(const KConfigGroup & m_configGroup)
00173 {
00174 setVisible(!m_configGroup.readEntry("isHiddenInSystray", false));
00175 m_streamlistwidget->readProperties(m_configGroup);
00176 }
00177
00178 void MainWindow::display_global_settings_dialog()
00179 {
00180
00181 if (KConfigDialog::showDialog("settings_general_dialog")) {
00182 return;
00183 };
00184
00185
00186 settings_general_dialog *dialog = new settings_general_dialog(this,
00187 "settings_general_dialog");
00188 dialog->show();
00189 }
00190
00191 void MainWindow::displayTipOfDay()
00192 {
00193 KTipDialog::showTip(this, "kstreamripper/tips", true);
00194 }
00195
00196 void MainWindow::prepareForExitingApp()
00197 {
00198 queryClose();
00199 QObjectList childrenList = children();
00200 foreach (QObject *child, childrenList) {
00201 delete child;
00202 };
00203 }
00204
00205 void MainWindow::showStreamdirectory(bool visible)
00206 {
00207 if (isVisible() && visible) {
00208 m_streamDirectory->setVisible(true);
00209 } else {
00210 m_streamDirectory->setVisible(false);
00211 };
00212 settings_general::setShowStreamdirectory(visible);
00213 settings_general::self()->writeConfig();
00214 }
00215
00216 void MainWindow::hideStreamdirectory()
00217 {
00218 showStreamdirectory(false);
00219 }
00220
00221 void MainWindow::setupActions()
00222 {
00223
00224 KStandardAction::preferences(this, SLOT(display_global_settings_dialog()),
00225 actionCollection());
00226
00227 KStandardAction::quit(kapp, SLOT(quit()), actionCollection());
00228
00229 showStreamdirectoryAction = new KToggleAction(this);
00230 showStreamdirectoryAction->setText(m_streamDirectory->windowTitle());
00231 QList<QKeySequence> showStreamdirectoryAction_tempShortcutList;
00232
00233
00234
00235
00236 showStreamdirectoryAction->setShortcuts(showStreamdirectoryAction_tempShortcutList);
00237 connect(showStreamdirectoryAction, SIGNAL(toggled(bool)),
00238 this, SLOT(showStreamdirectory(bool)));
00239 connect(m_streamDirectory, SIGNAL(willAcceptCloseEventFromWindowSystem(bool)),
00240 showStreamdirectoryAction, SLOT(setChecked(bool)));
00241 actionCollection()->addAction("showStreamdirectory", showStreamdirectoryAction);
00242 showStreamdirectoryAction->setChecked(settings_general::showStreamdirectory());
00243
00244 KAction *importKradioripperSettingsAction = new KAction(this);
00245 importKradioripperSettingsAction->setText(
00246 i18nc("@action:inmenu", "Import KRadioRipper settings"));
00247 connect(importKradioripperSettingsAction, SIGNAL(triggered(bool)),
00248 this, SLOT(askForKradioripperImport()));
00249 actionCollection()->addAction("importKradioripperSettings", importKradioripperSettingsAction);
00250
00251 KStandardAction::tipOfDay(this, SLOT(displayTipOfDay()), actionCollection());
00252 }
00253
00254 void MainWindow::askForKradioripperImport()
00255 {
00256 importKradioripperSettings::askForImport();
00257 }