Skip to content

Commit 57b9b1c

Browse files
committed
first cut notifications via tray icon popup
1 parent abe4b39 commit 57b9b1c

File tree

7 files changed

+173
-40
lines changed

7 files changed

+173
-40
lines changed

cmst.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ INSTALLS += target
1212

1313
documentation.path = /usr/share/man/man1
1414
documentation.files = ./text/cmst.1.gz
15+
documentation.extra = gzip --keep --force ./text/cmst.1
1516
INSTALLS += documentation
1617

1718
# dbus

code/control_box/controlbox.cpp

Lines changed: 144 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ ControlBox::ControlBox(const QCommandLineParser& parser, QWidget *parent)
148148
vlist_counter << QVariant::fromValue(QDBusObjectPath("/org/monkeybusiness/Counter")) << counter_accuracy << counter_period;;
149149
iface_manager->callWithArgumentList(QDBus::NoBlock, "RegisterCounter", vlist_counter);
150150
}
151+
152+
// connect some dbus signals to our slots
153+
QDBusConnection::systemBus().connect(DBUS_SERVICE, DBUS_PATH, DBUS_MANAGER, "PropertyChanged", this, SLOT(dbsPropertyChanged(QString, QDBusVariant)));
154+
QDBusConnection::systemBus().connect(DBUS_SERVICE, DBUS_PATH, DBUS_MANAGER, "ServicesChanged", this, SLOT(dbsServicesChanged()));
151155
} // else have valid connection
152-
} // else have connected sessionBus
153-
156+
} // else have connected systemBus
157+
154158
// setup the dialog
155159
// timer to scan for wifi services now and again
156160
wifi_timer = new QTimer(this);
@@ -191,19 +195,19 @@ ControlBox::ControlBox(const QCommandLineParser& parser, QWidget *parent)
191195
connect(ui.pushButton_license, SIGNAL(clicked()), this, SLOT(showLicense()));
192196
connect(ui.pushButton_change_log, SIGNAL(clicked()), this, SLOT(showChangeLog()));
193197
connect(ui.tableWidget_services, SIGNAL (cellClicked(int, int)), this, SLOT(enableMoveButtons(int, int)));
194-
connect(ui.checkBox_hidecnxn, SIGNAL (toggled(bool)), this, SLOT(propertyChanged()));
198+
connect(ui.checkBox_hidecnxn, SIGNAL (toggled(bool)), this, SLOT(dbsServicesChanged()));
195199

196200
// tray icon - disable it if we specifiy that option on the commandline
197201
// otherwise set a singleshot timer to create the tray icon and showMinimized
198202
// or showMaximized.
199203
trayicon = 0;
200204
if (parser.isSet("disable-tray-icon")) {
201205
ui.checkBox_hideIcon->setDisabled(true);
202-
this->showMaximized(); // no place to minimize to, so showMaximized
206+
this->showNormal(); // no place to minimize to, so showMaximized
203207
} // if
204208
else {
205209
bool ok;
206-
const short mintrigger = 500; // minimum time (milliseconds) to wait before starting the tray icon
210+
const short mintrigger = 100; // minimum time (milliseconds) to wait before starting the tray icon
207211
int timeout = parser.value("wait-time").toInt(&ok, 10);
208212
if (! ok) timeout = 0;
209213
timeout *= 1000;
@@ -220,10 +224,6 @@ ControlBox::ControlBox(const QCommandLineParser& parser, QWidget *parent)
220224
//// turn network cards on or off globally based on checkbox
221225
toggleOfflineMode(ui.checkBox_devicesoff->isChecked() );
222226

223-
// connect some dbus signals to our slots
224-
QDBusConnection::systemBus().connect(DBUS_SERVICE, DBUS_PATH, DBUS_MANAGER, "PropertyChanged", this, SLOT(propertyChanged()));
225-
QDBusConnection::systemBus().connect(DBUS_SERVICE, DBUS_PATH, DBUS_MANAGER, "ServicesChanged", this, SLOT(propertyChanged()));
226-
227227
// start the timer
228228
wifi_timer->start();
229229

@@ -321,9 +321,6 @@ void ControlBox::moveService(QAction* act)
321321
else
322322
iface_serv->call(QDBus::NoBlock, "MoveAfter", QVariant::fromValue(targetobj) );
323323
delete iface_serv;
324-
325-
// update the widgets
326-
this->propertyChanged();
327324

328325
return;
329326
}
@@ -409,9 +406,6 @@ void ControlBox::connectPressed()
409406
iface_serv->call(QDBus::NoBlock, "Connect");
410407
delete iface_serv;
411408

412-
// update the widgets
413-
this->propertyChanged();
414-
415409
return;
416410
}
417411

@@ -434,8 +428,6 @@ void ControlBox::disconnectPressed()
434428
iface_serv->call(QDBus::NoBlock, "Disconnect");
435429
delete iface_serv;
436430

437-
this->propertyChanged();
438-
439431
return;
440432
}
441433

@@ -458,18 +450,117 @@ void ControlBox::removePressed()
458450
QDBusInterface* iface_serv = new QDBusInterface(DBUS_SERVICE, wifi_list.at(list.at(0)->row()).objpath.path(), "net.connman.Service", QDBusConnection::systemBus(), this);
459451
iface_serv->call(QDBus::NoBlock, "Remove");
460452
delete iface_serv;
461-
462-
this->propertyChanged();
463-
453+
464454
return;
465455
}
466456

457+
// dbs slots are slots to receive DBus Signals
458+
//
459+
// Slot called whenever DBUS issues a PropertyChanged signal
460+
void ControlBox::dbsPropertyChanged(QString name, QDBusVariant dbvalue)
461+
{
462+
// refresh properties from connman and update display widgets
463+
updateDisplayWidgets();
464+
465+
QVariant value = dbvalue.variant();
466+
467+
// offlinemode property
468+
if (name.contains("OfflineMode", Qt::CaseInsensitive)) {
469+
if (value.toBool()) sendNotifications(
470+
QString(tr("Offline Mode Engaged")),
471+
QIcon(":/icons/images/interface/golfball_green.png"),
472+
QSystemTrayIcon::Information );
473+
else sendNotifications(
474+
QString(tr("Offline Mode Disabled")),
475+
QIcon(":/icons/images/interface/golfball_red.png"),
476+
QSystemTrayIcon::Information );
477+
} // if contains offlinemode
478+
479+
// state property
480+
else if (name.contains("State", Qt::CaseInsensitive)) {
481+
if (value.toString().contains("online", Qt::CaseInsensitive)) {
482+
QString type = "";
483+
QString name = "";
484+
485+
// find the online service
486+
if (properties_map.value("State").toString().contains("online", Qt::CaseInsensitive) ) {
487+
for (int i =0; i < services_list.size(); ++i) {
488+
if (services_list.at(i).objmap.value("State").toString().contains("online", Qt::CaseInsensitive)) {
489+
type = services_list.at(i).objmap.value("Type").toString();
490+
type = type.replace(0, 1, type.left(1).toUpper() );
491+
name = services_list.at(i).objmap.value("Name").toString();
492+
name = name.replace (0, 1, name.left(1).toUpper() );
493+
break;
494+
} // if
495+
} // for
496+
} // if state contains online
497+
498+
// notification text and icons if online
499+
if (type.contains("wifi", Qt::CaseInsensitive)) {
500+
sendNotifications(
501+
QString(tr("%1 (%2) Online")).arg(type).arg(name),
502+
b_useicontheme ?
503+
QIcon::fromTheme("network-transmit-receive", QIcon(":/icons/images/systemtray/wl000.png")).pixmap(QSize(16,16)) :
504+
QIcon(":/icons/images/systemtray/wl000.png"),
505+
QSystemTrayIcon::Information );
506+
} // if wifi
507+
else {
508+
sendNotifications(
509+
QString(tr("%1 (%2) Online")).arg(type).arg(name),
510+
b_useicontheme ?
511+
QIcon::fromTheme("network-transmit-receive", QIcon(":/icons/images/systemtray/wired_established.png")).pixmap(QSize(16,16)) :
512+
QIcon(":/icons/images/systemtray/wired_established.png"),
513+
QSystemTrayIcon::Information );
514+
} // else (probably ethernet)
515+
} // if value online
516+
517+
// ready state
518+
else if (value.toString().contains("ready", Qt::CaseInsensitive)) {
519+
sendNotifications(
520+
QString(tr("Connection Ready")),
521+
b_useicontheme ?
522+
QIcon::fromTheme("network-idle", QIcon(":/icons/images/interface/connect_creating.png")).pixmap(QSize(16,16)) :
523+
QIcon(":/icons/images/interface/connect_creating.png"),
524+
QSystemTrayIcon::Information );
525+
} // if ready
467526

527+
// anyother state, report as offline
528+
else {
529+
sendNotifications(
530+
QString(tr("Offline")),
531+
b_useicontheme ?
532+
QIcon::fromTheme("network-offline", QIcon(":/icons/images/interface/connect_no.png")).pixmap(QSize(16,16)) :
533+
QIcon (":/icons/images/interface/connect_no.png"),
534+
QSystemTrayIcon::Information );
535+
} // else offline
536+
} // else state
537+
538+
return;
539+
}
540+
468541
//
469-
// Slot called whenever a the DBUS issues a PropertyChanged signal
470-
void ControlBox::propertyChanged()
542+
// Slot called whenever DBUS issues a ServicesChanged signal
543+
void ControlBox::dbsServicesChanged()
471544
{
472545
updateDisplayWidgets();
546+
547+
return;
548+
}
549+
550+
//
551+
// Slot called whenever the online service object issues a PropertyChanged signal on DBUS
552+
void ControlBox::dbsServicePropertyChanged(QString property, QDBusVariant dbvalue)
553+
{
554+
QVariant value = dbvalue.variant();
555+
556+
// process errrors
557+
if (property.contains("Error", Qt::CaseInsensitive) ) {
558+
sendNotifications(
559+
QString(tr("Service Error: %1")).arg(value.toString()),
560+
QIcon(":/icons/images/interface/cancel.png"),
561+
QSystemTrayIcon::Critical);
562+
}
563+
473564
return;
474565
}
475566

@@ -541,7 +632,7 @@ void ControlBox::togglePowered(int row)
541632

542633
QDBusMessage reply = iface_tech->callWithArgumentList(QDBus::AutoDetect, "SetProperty", vlist);
543634
if (reply.type() == QDBusMessage::ReplyMessage)
544-
this ->propertyChanged();
635+
this->updateDisplayWidgets();
545636
else
546637
QMessageBox::warning(this, tr("CMST Warning"),
547638
tr("<center><b>We received a DBUS reply message indicating an error while trying to send the toggle power request to connman.</b></center>"
@@ -710,11 +801,13 @@ void ControlBox::updateDisplayWidgets()
710801
// Find the service marked "online"
711802
if (properties_map.value("State").toString().contains("online", Qt::CaseInsensitive) ) {
712803
for (int i =0; i < services_list.size(); ++i) {
713-
if (services_list.at(i).objmap.value("State").toString().contains("online", Qt::CaseInsensitive))
714-
service_online = services_list.at(i).objpath;
715-
break;
804+
if (services_list.at(i).objmap.value("State").toString().contains("online", Qt::CaseInsensitive)) {
805+
service_online = services_list.at(i).objpath;
716806
} // if
807+
QDBusConnection::systemBus().disconnect(DBUS_SERVICE, services_list.at(i).objpath.path(), "net.connman.Service", "PropertyChanged", this, SLOT(dbsServicePropertyChanged(QString, QDBusVariant)));
808+
QDBusConnection::systemBus().connect(DBUS_SERVICE, services_list.at(i).objpath.path(), "net.connman.Service", "PropertyChanged", this, SLOT(dbsServicePropertyChanged(QString, QDBusVariant)));
717809
} // for
810+
} // if state contains onlinew
718811
else service_online = QDBusObjectPath();
719812

720813
// rebuild our pages
@@ -797,13 +890,14 @@ void ControlBox::assemblePage1()
797890
bt = technologies_list.at(row).objmap.value("Powered").toBool();
798891
idButton* qpb02 = new idButton(this, row);
799892
connect (qpb02, SIGNAL(clickedID(int)), this, SLOT(togglePowered(int)));
893+
QString padding = " ";
800894
if (bt ) {
801-
qpb02->setText(tr(" On", "powered"));
895+
qpb02->setText(tr("%1On", "powered").arg(padding));
802896
qpb02->setIcon(QPixmap(":/icons/images/interface/golfball_green.png"));
803897
qpb02->setDown(true);
804898
}
805899
else {
806-
qpb02->setText(tr(" Off", "powered"));
900+
qpb02->setText(tr("%1Off", "powered").arg(padding));
807901
qpb02->setIcon(QPixmap(":/icons/images/interface/golfball_red.png"));
808902
qpb02->setDown(false);
809903
}
@@ -856,8 +950,7 @@ void ControlBox::assemblePage1()
856950
else {
857951
ui.tableWidget_services->showColumn(2);
858952
ui.tableWidget_services->horizontalHeader()->resizeSection(1, ui.tableWidget_services->horizontalHeader()->defaultSectionSize());
859-
}
860-
953+
}
861954
} // services for loop
862955

863956
// resize the services column 0 to contents
@@ -1033,14 +1126,14 @@ void ControlBox::assembleTrayIcon()
10331126
else if (str > 60 ) trayicon->setIcon(QIcon(":/icons/images/systemtray/wl075.png"));
10341127
else if (str > 40 ) trayicon->setIcon(QIcon(":/icons/images/systemtray/wl050.png"));
10351128
else if (str > 20 ) trayicon->setIcon(QIcon(":/icons/images/systemtray/wl025.png"));
1036-
else trayicon->setIcon(QIcon(":/icons/images/systemtray/wl00.png"));
1037-
} // else
1129+
else trayicon->setIcon(QIcon(":/icons/images/systemtray/wl000.png"));
1130+
} // else use our built in icons
10381131
} // if wifi connection
10391132
break;
1040-
} // if service online
1133+
} // if the service is online
10411134
} // for
10421135
} // services if no error
1043-
} // if online
1136+
} // if the state is online
10441137
else {
10451138
b_useicontheme ?
10461139
trayicon->setIcon(QIcon::fromTheme("network-offline", QIcon(":/icons/images/systemtray/connect_no.png")) ) :
@@ -1067,7 +1160,7 @@ void ControlBox::assembleTrayIcon()
10671160
return;
10681161
}
10691162

1070-
//Handler for left click on tray icon
1163+
// Handler for left click on tray icon
10711164
void ControlBox::iconActivated(QSystemTrayIcon::ActivationReason reason)
10721165
{
10731166
//Only handling left click case
@@ -1101,6 +1194,7 @@ void ControlBox::writeSettings()
11011194
settings->setValue("services_less", ui.checkBox_hidecnxn->isChecked() );
11021195
settings->setValue("enable_interface_tooltips", ui.checkBox_enableinterfacetooltips->isChecked() );
11031196
settings->setValue("enable_systemtray_tooltips", ui.checkBox_enablesystemtraytooltips->isChecked() );
1197+
settings->setValue("enable_systemtray_notications", ui.checkBox_enablesystemtraynotification->isChecked() );
11041198
settings->endGroup();
11051199

11061200
return;
@@ -1124,6 +1218,7 @@ void ControlBox::readSettings()
11241218
ui.checkBox_hidecnxn->setChecked(settings->value("services_less").toBool() );
11251219
ui.checkBox_enableinterfacetooltips->setChecked(settings->value("enable_interface_tooltips").toBool() );
11261220
ui.checkBox_enablesystemtraytooltips->setChecked(settings->value("enable_systemtray_tooltips").toBool() );
1221+
ui.checkBox_enablesystemtraynotification->setChecked(settings->value("enable_systemtray_notications").toBool() );
11271222
settings->endGroup();
11281223

11291224
return;
@@ -1173,6 +1268,20 @@ void ControlBox::createSystemTrayIcon(bool b_startminimized)
11731268
return;
11741269
}
11751270

1271+
//
1272+
// Function to show notifications (if desired by the user). Called from
1273+
// Called from the functions we connect dbus signals to, for instance
1274+
// dbsPropertyChanged(), stateChanged();
1275+
void ControlBox::sendNotifications(const QString& text, QIcon icon, QSystemTrayIcon::MessageIcon sticon)
1276+
{
1277+
// if we want system tray notifications
1278+
if (ui.checkBox_enablesystemtraynotification->isChecked() && QSystemTrayIcon::isSystemTrayAvailable() ) {
1279+
trayicon->showMessage(PROGRAM_NAME, text, sticon);
1280+
}
1281+
1282+
return;
1283+
}
1284+
11761285
//
11771286
// Function to query connman.manager.GetProperties
11781287
// Return a bool, true on success, false otherwise

code/control_box/controlbox.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class ControlBox : public QDialog
145145
void assemblePage4();
146146
void assembleTrayIcon();
147147
void createSystemTrayIcon(bool);
148+
void sendNotifications(const QString&, QIcon = QIcon(), QSystemTrayIcon::MessageIcon = QSystemTrayIcon::Information);
148149
bool getProperties();
149150
bool getTechnologies();
150151
bool getServices();
@@ -162,11 +163,12 @@ class ControlBox : public QDialog
162163
void connectPressed();
163164
void disconnectPressed();
164165
void removePressed();
165-
void propertyChanged();
166+
void dbsPropertyChanged(QString,QDBusVariant);
167+
void dbsServicesChanged();
168+
void dbsServicePropertyChanged(QString, QDBusVariant);
166169
void scanWifi();
167170
void toggleOfflineMode(bool);
168171
void toggleTrayIcon(bool);
169-
//void togglePowered(int, int);
170172
void togglePowered(int);
171173
void minMaxWindow(QAction* = 0);
172174
void getServiceDetails(int);

code/control_box/ui/controlbox.ui

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,29 @@
854854
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked the system tray icon will popup a status message when you hover the mouse over it.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
855855
</property>
856856
<property name="text">
857-
<string>&amp;Enable System Tray Popup</string>
857+
<string>&amp;Enable System Tray Popups</string>
858858
</property>
859859
<property name="checked">
860860
<bool>true</bool>
861861
</property>
862862
</widget>
863863
</item>
864+
<item row="2" column="0">
865+
<widget class="QCheckBox" name="checkBox_enablesystemtraynotification">
866+
<property name="enabled">
867+
<bool>true</bool>
868+
</property>
869+
<property name="toolTip">
870+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enable notifications from the systemtray&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
871+
</property>
872+
<property name="whatsThis">
873+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If checked the system tray will popup a notify message when a significant connman related event is received.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
874+
</property>
875+
<property name="text">
876+
<string>Enable System Tray &amp;Notifications</string>
877+
</property>
878+
</widget>
879+
</item>
864880
</layout>
865881
</widget>
866882
</item>

code/resource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ DEALINGS IN THE SOFTWARE.
3434

3535
///////////////////////////////// Program Values ///////////////////////
3636
// Program Info
37-
#define VERSION "14.06.07-1"
37+
#define VERSION "14.06.14-1"
3838
#define RELEASE_DATE "10 May 2014"
3939
#define COPYRIGHT_DATE "2013-2014"
4040

text/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<li>Limit the amount the dialog can shrink.</li>
1616
<li>Replaced Nuvola icons with AwOken icons.</li>
1717
<li>A manpage is now provided and installed.</li>
18+
<li>The system tray icon can optionally show notify messages in popups.</li>
1819
</ul>
1920
<br><b>2014.05.10</b>
2021
<ul>

0 commit comments

Comments
 (0)