Changeset 42
- Timestamp:
- 01/07/08 16:25:46 (4 years ago)
- Files:
-
- 5 edited
-
gui/main_window.cpp (modified) (8 diffs)
-
gui/main_window.h (modified) (2 diffs)
-
gui/preferences_dialog.cpp (modified) (3 diffs)
-
gui/preferences_dialog.ui (modified) (3 diffs)
-
main.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
gui/main_window.cpp
r41 r42 2 2 #include <QtGui> 3 3 #include <QIcon> 4 #include <Q Debug>4 #include <QString> 5 5 6 6 #include "main_window.h" … … 10 10 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) 11 11 { 12 //Setup and set visible. 12 13 setupUi(this); 14 setVisible(true); 13 15 14 16 slidingVolume = false; … … 19 21 20 22 //Tray stuf 21 setupTrayIcon(); 22 if (settings.value("systemtray").toBool()) { 23 if (setupTrayIcon() && settings.value("systemtray").toBool()) { 23 24 trayIcon->show(); 24 25 } … … 79 80 } 80 81 81 /*MainWindow::~MainWindow()82 {83 qDebug("Closing main window...");84 }*/85 86 82 void MainWindow::closeEvent(QCloseEvent *event) 87 83 { 88 if (trayIcon->isVisible()) { 89 QMessageBox::information(this, tr("Systray"), 90 tr("The program will keep running in the " 91 "system tray. To terminate the program, " 92 "choose <b>Quit</b> in the context menu " 93 "of the system tray entry.")); 84 if (trayIcon != NULL && trayIcon->isVisible()) { 94 85 hide(); 95 86 event->ignore(); … … 97 88 } 98 89 99 void MainWindow::setupTrayIcon() 100 { 90 bool MainWindow::setupTrayIcon() 91 { 92 if (!QSystemTrayIcon::isSystemTrayAvailable()) { 93 trayIcon = NULL; 94 return false; 95 } 96 101 97 trayIcon = new QSystemTrayIcon(this); 102 98 trayIconMenu = new QMenu(this); … … 127 123 trayIcon->setIcon(icon); 128 124 trayIcon->setToolTip("QtMPC"); 125 126 return true; 129 127 } 130 128 … … 132 130 { 133 131 PreferencesDialog pref(this); 134 connect(&pref, SIGNAL(systemTraySet(bool)), trayIcon, SLOT(setVisible(bool))); 132 if (trayIcon != NULL) 133 connect(&pref, SIGNAL(systemTraySet(bool)), trayIcon, SLOT(setVisible(bool))); 135 134 pref.exec(); 136 135 } … … 210 209 211 210 playlistModel.updateCurrentSong(song->id); 211 212 if (settings.value("systemtrayPopup").toBool() && trayIcon != NULL && trayIcon->isVisible() && isHidden()) { 213 if (!song->title.isEmpty() && !song->artist.isEmpty() && !song->album.isEmpty()) { 214 trayIcon->showMessage(song->artist + " - " + song->title, 215 "album:" + song->album + "\n" + 216 "track:" + QString::number(song->track) + "\n" + 217 "time:" + QString::number(song->time) + "\n", 218 QSystemTrayIcon::Information, 5000); 219 } 220 } 212 221 213 222 delete song; -
gui/main_window.h
r40 r42 21 21 public: 22 22 MainWindow(QWidget *parent = 0); 23 //~MainWindow();24 23 25 24 protected: … … 37 36 QIcon icon; 38 37 39 voidsetupTrayIcon();38 bool setupTrayIcon(); 40 39 QAction *minimizeAction; 41 40 QAction *maximizeAction; -
gui/preferences_dialog.cpp
r30 r42 7 7 8 8 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonPressed(QAbstractButton *))); 9 10 9 loadSettings(); 11 10 } … … 17 16 passwordLineEdit->setText(settings.value("connection/password", "").toString()); 18 17 systemTrayCheckBox->setChecked(settings.value("systemtray").toBool()); 18 if (settings.value("systemtray").toBool()) { 19 systemTrayPopup->setChecked(settings.value("systemtrayPopup").toBool()); 20 } else { 21 systemTrayPopup->setEnabled(false); 22 } 19 23 } 20 24 … … 32 36 settings.setValue("connection/password", passwordLineEdit->text()); 33 37 settings.setValue("systemtray", systemTrayCheckBox->isChecked()); 38 if (systemTrayCheckBox->isChecked()) { 39 settings.setValue("systemtrayPopup", systemTrayPopup->isChecked()); 40 } else { 41 settings.setValue("systemtrayPopup", false); 42 } 34 43 emit systemTraySet(systemTrayCheckBox->isChecked()); 35 44 break; -
gui/preferences_dialog.ui
r29 r42 6 6 <x>0</x> 7 7 <y>0</y> 8 <width>4 11</width>9 <height>2 17</height>8 <width>451</width> 9 <height>283</height> 10 10 </rect> 11 11 </property> … … 13 13 <string>QtMPC Preferences</string> 14 14 </property> 15 <layout class="QVBoxLayout" > 16 <item> 17 <layout class="QHBoxLayout" > 18 <item> 19 <widget class="QLabel" name="label" > 20 <property name="text" > 21 <string>MPD host:</string> 22 </property> 23 </widget> 24 </item> 25 <item> 26 <widget class="QLineEdit" name="hostLineEdit" /> 27 </item> 28 </layout> 29 </item> 30 <item> 31 <layout class="QHBoxLayout" > 32 <item> 33 <widget class="QLabel" name="label_2" > 34 <property name="text" > 35 <string>MPD port:</string> 36 </property> 37 </widget> 38 </item> 39 <item> 40 <widget class="QSpinBox" name="portSpinBox" > 41 <property name="minimum" > 42 <number>1</number> 43 </property> 44 <property name="maximum" > 45 <number>60000</number> 46 </property> 47 <property name="value" > 48 <number>6600</number> 49 </property> 50 </widget> 51 </item> 52 </layout> 53 </item> 54 <item> 55 <layout class="QHBoxLayout" > 56 <item> 57 <widget class="QLabel" name="label_3" > 58 <property name="text" > 59 <string>Password:</string> 60 </property> 61 </widget> 62 </item> 63 <item> 64 <widget class="QLineEdit" name="passwordLineEdit" /> 65 </item> 66 </layout> 67 </item> 68 <item> 69 <layout class="QHBoxLayout" > 70 <item> 71 <spacer> 72 <property name="orientation" > 73 <enum>Qt::Horizontal</enum> 74 </property> 75 <property name="sizeHint" > 76 <size> 77 <width>30</width> 78 <height>20</height> 79 </size> 80 </property> 81 </spacer> 82 </item> 83 <item> 84 <widget class="QCheckBox" name="connectCheckBox" > 85 <property name="enabled" > 86 <bool>false</bool> 87 </property> 88 <property name="text" > 89 <string>Connect on Startup</string> 90 </property> 91 </widget> 92 </item> 93 </layout> 94 </item> 95 <item> 96 <layout class="QHBoxLayout" > 97 <item> 98 <spacer> 99 <property name="orientation" > 100 <enum>Qt::Horizontal</enum> 101 </property> 102 <property name="sizeHint" > 103 <size> 104 <width>30</width> 105 <height>20</height> 106 </size> 107 </property> 108 </spacer> 109 </item> 110 <item> 111 <widget class="QCheckBox" name="systemTrayCheckBox" > 112 <property name="enabled" > 113 <bool>true</bool> 114 </property> 115 <property name="text" > 116 <string>Show in System tray</string> 117 </property> 118 </widget> 119 </item> 120 </layout> 121 </item> 122 <item> 123 <widget class="QDialogButtonBox" name="buttonBox" > 124 <property name="orientation" > 125 <enum>Qt::Horizontal</enum> 126 </property> 127 <property name="standardButtons" > 128 <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> 129 </property> 130 </widget> 131 </item> 132 </layout> 15 <widget class="QDialogButtonBox" name="buttonBox" > 16 <property name="geometry" > 17 <rect> 18 <x>9</x> 19 <y>247</y> 20 <width>433</width> 21 <height>27</height> 22 </rect> 23 </property> 24 <property name="orientation" > 25 <enum>Qt::Horizontal</enum> 26 </property> 27 <property name="standardButtons" > 28 <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> 29 </property> 30 </widget> 31 <widget class="QWidget" name="" > 32 <property name="geometry" > 33 <rect> 34 <x>9</x> 35 <y>9</y> 36 <width>431</width> 37 <height>221</height> 38 </rect> 39 </property> 40 <layout class="QVBoxLayout" > 41 <item> 42 <layout class="QHBoxLayout" > 43 <item> 44 <widget class="QLabel" name="label" > 45 <property name="text" > 46 <string>MPD host:</string> 47 </property> 48 </widget> 49 </item> 50 <item> 51 <widget class="QLineEdit" name="hostLineEdit" /> 52 </item> 53 </layout> 54 </item> 55 <item> 56 <layout class="QHBoxLayout" > 57 <item> 58 <widget class="QLabel" name="label_2" > 59 <property name="text" > 60 <string>MPD port:</string> 61 </property> 62 </widget> 63 </item> 64 <item> 65 <widget class="QSpinBox" name="portSpinBox" > 66 <property name="minimum" > 67 <number>1</number> 68 </property> 69 <property name="maximum" > 70 <number>60000</number> 71 </property> 72 <property name="value" > 73 <number>6600</number> 74 </property> 75 </widget> 76 </item> 77 </layout> 78 </item> 79 <item> 80 <layout class="QHBoxLayout" > 81 <item> 82 <widget class="QLabel" name="label_3" > 83 <property name="text" > 84 <string>Password:</string> 85 </property> 86 </widget> 87 </item> 88 <item> 89 <widget class="QLineEdit" name="passwordLineEdit" /> 90 </item> 91 </layout> 92 </item> 93 <item> 94 <layout class="QHBoxLayout" > 95 <item> 96 <spacer> 97 <property name="orientation" > 98 <enum>Qt::Horizontal</enum> 99 </property> 100 <property name="sizeHint" > 101 <size> 102 <width>30</width> 103 <height>20</height> 104 </size> 105 </property> 106 </spacer> 107 </item> 108 <item> 109 <widget class="QCheckBox" name="connectCheckBox" > 110 <property name="enabled" > 111 <bool>false</bool> 112 </property> 113 <property name="text" > 114 <string>Connect on Startup</string> 115 </property> 116 </widget> 117 </item> 118 </layout> 119 </item> 120 <item> 121 <layout class="QHBoxLayout" > 122 <item> 123 <spacer> 124 <property name="orientation" > 125 <enum>Qt::Horizontal</enum> 126 </property> 127 <property name="sizeHint" > 128 <size> 129 <width>30</width> 130 <height>20</height> 131 </size> 132 </property> 133 </spacer> 134 </item> 135 <item> 136 <widget class="QCheckBox" name="systemTrayCheckBox" > 137 <property name="enabled" > 138 <bool>true</bool> 139 </property> 140 <property name="text" > 141 <string>Show in System tray</string> 142 </property> 143 </widget> 144 </item> 145 </layout> 146 </item> 147 <item> 148 <layout class="QHBoxLayout" > 149 <item> 150 <spacer> 151 <property name="orientation" > 152 <enum>Qt::Horizontal</enum> 153 </property> 154 <property name="sizeHint" > 155 <size> 156 <width>171</width> 157 <height>35</height> 158 </size> 159 </property> 160 </spacer> 161 </item> 162 <item> 163 <widget class="QCheckBox" name="systemTrayPopup" > 164 <property name="text" > 165 <string>Show Popup message</string> 166 </property> 167 </widget> 168 </item> 169 </layout> 170 </item> 171 </layout> 172 </widget> 133 173 </widget> 134 174 <resources/> … … 166 206 </hints> 167 207 </connection> 208 <connection> 209 <sender>systemTrayCheckBox</sender> 210 <signal>clicked(bool)</signal> 211 <receiver>systemTrayPopup</receiver> 212 <slot>setEnabled(bool)</slot> 213 <hints> 214 <hint type="sourcelabel" > 215 <x>363</x> 216 <y>173</y> 217 </hint> 218 <hint type="destinationlabel" > 219 <x>360</x> 220 <y>209</y> 221 </hint> 222 </hints> 223 </connection> 168 224 </connections> 169 225 </ui> -
main.cpp
r29 r42 11 11 QApplication::setOrganizationName("lowblogprojects"); 12 12 13 if (!QSystemTrayIcon::isSystemTrayAvailable()) {14 QMessageBox::critical(0, QObject::tr("Systray"),15 QObject::tr("I couldn't detect any system tray on this system."));16 return 1;17 }18 19 13 MainWindow w; 20 14 w.show();
Note: See TracChangeset
for help on using the changeset viewer.
