Skip to content

Commit 00ef5d0

Browse files
committed
Merge pull request #65 from diegorubin/feature-#9-work-icon
Show status on systray icon.
2 parents cd443ce + 9e0b48a commit 00ef5d0

File tree

6 files changed

+60
-13
lines changed

6 files changed

+60
-13
lines changed

data/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
uidir = $(datadir)/gnomato
22
ui_DATA = \
33
tomato.png \
4+
tomato-green.png \
5+
tomato-gray.png \
46
gnomato.ui
57

68
gsettings_SCHEMAS = com.diegorubin.gnomato.gschema.xml

data/tomato-gray.png

7.69 KB
Loading

data/tomato-green.png

11.4 KB
Loading

src/main.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ int main(int argc, char **argv)
317317
return 1;
318318
}
319319

320-
Glib::RefPtr<Gtk::StatusIcon> systray =
321-
Gtk::StatusIcon::create_from_file(GNOMATO_DATADIR "/tomato.png");
322-
323320
winMain = 0;
324321
refBuilder->get_widget_derived("winMain", winMain);
325322

@@ -345,7 +342,7 @@ int main(int argc, char **argv)
345342
if(winMain)
346343
{
347344
winMain->set_icon_from_file(GNOMATO_DATADIR "/tomato.png");
348-
winMain->set_systray(systray);
345+
winMain->set_gray_icon();
349346
winMain->show();
350347
kit.run();
351348
}

src/win_main.cc

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ WinMain::WinMain(BaseObjectType* cobject,
3939

4040
pe = new PythonExecutor();
4141

42+
set_systray();
43+
4244
// get widgets
4345
m_refGlade->get_widget("lblDisplay", lblDisplay);
4446
m_refGlade->get_widget("lblCycle", lblCycle);
@@ -147,9 +149,10 @@ WinMain::~WinMain()
147149
if(pe != NULL) delete(pe);
148150
}
149151

150-
void WinMain::set_systray(Glib::RefPtr<StatusIcon> tray)
152+
void WinMain::set_systray()
151153
{
152-
systray = tray;
154+
155+
systray = Gtk::StatusIcon::create_from_file(GNOMATO_DATADIR "/tomato.png");
153156

154157
//criacao do menu para o systray
155158
actMenu = Gtk::ActionGroup::create();
@@ -289,14 +292,27 @@ void WinMain::load_tasks()
289292
trvTasks->append_column(_("Title"), mdlColumn.title);
290293
}
291294

295+
void WinMain::notify_with_gray_icon(const char *message)
296+
{
297+
notify(GNOMATO_DATADIR "/tomato-gray.png", message);
298+
}
299+
300+
void WinMain::notify_with_green_icon(const char *message)
301+
{
302+
notify(GNOMATO_DATADIR "/tomato-green.png", message);
303+
}
304+
292305
void WinMain::notify(const char *message)
306+
{
307+
notify(GNOMATO_DATADIR "/tomato.png", message);
308+
}
309+
310+
void WinMain::notify(const char *icon, const char *message)
293311
{
294312
NotifyNotification *notMessage;
295313
GError *error = NULL;
296314

297-
notMessage = notify_notification_new("Gnomato",
298-
message,
299-
GNOMATO_DATADIR "/tomato.png");
315+
notMessage = notify_notification_new("Gnomato", message, icon);
300316

301317
notify_notification_set_timeout(notMessage,3000);
302318

@@ -418,13 +434,19 @@ void WinMain::on_button_start_clicked()
418434
timeout.disconnect();
419435

420436
execute("on_pause");
437+
set_gray_icon();
421438

422439
}else{
423440
started = true;
424441
btnStart->set_label(_("Pause"));
425442
timeout = Glib::signal_timeout().connect(timer, 1000);
426443

427444
execute("on_start");
445+
if(cycle_number % 2) {
446+
set_red_icon();
447+
} else {
448+
set_green_icon();
449+
}
428450

429451
}
430452
}
@@ -524,8 +546,9 @@ bool WinMain::on_timeout(int timer_number)
524546
if(cycle_number % 2){
525547

526548
execute("on_break");
527-
528549
notify(_("Take a break"));
550+
set_red_icon();
551+
529552
inc_current_task();
530553
if(cycle_number == 7)
531554
time_elapsed = atoi(configs.long_interval.c_str()) * 60;
@@ -536,7 +559,8 @@ bool WinMain::on_timeout(int timer_number)
536559

537560
execute("on_work");
538561

539-
notify(_("End of break"));
562+
notify_with_green_icon(_("End of break"));
563+
set_green_icon();
540564
time_elapsed = atoi(configs.work_interval.c_str()) * 60;
541565
}
542566

@@ -557,7 +581,7 @@ bool WinMain::on_timeout(int timer_number)
557581
bool WinMain::on_inactive_timeout(int timer_number)
558582
{
559583
if(!(currentTask && started)) {
560-
notify(_("are you not doing anything?"));
584+
notify_with_gray_icon(_("are you not doing anything?"));
561585
}
562586

563587
check_inactive.disconnect();
@@ -681,6 +705,21 @@ Glib::ustring WinMain::get_current_list()
681705
return cmbLists->get_active_text();
682706
}
683707

708+
void WinMain::set_green_icon()
709+
{
710+
systray->set_from_file(GNOMATO_DATADIR "/tomato-green.png");
711+
}
712+
713+
void WinMain::set_gray_icon()
714+
{
715+
systray->set_from_file(GNOMATO_DATADIR "/tomato-gray.png");
716+
}
717+
718+
void WinMain::set_red_icon()
719+
{
720+
systray->set_from_file(GNOMATO_DATADIR "/tomato.png");
721+
}
722+
684723
WinMain::TasksView::TasksView(BaseObjectType* cobject,
685724
const Glib::RefPtr<Gtk::Builder>& refGlade)
686725
: Gtk::TreeView(cobject),

src/win_main.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class WinMain: public Gtk::Window
5454
void force_show();
5555
void load_lists();
5656
void load_tasks();
57-
void set_systray(Glib::RefPtr<Gtk::StatusIcon> tray);
57+
58+
void set_green_icon();
59+
void set_red_icon();
60+
void set_gray_icon();
5861

5962
Glib::ustring get_current_time();
6063
Glib::ustring get_current_task_title();
@@ -156,7 +159,12 @@ class WinMain: public Gtk::Window
156159
std::string generate_cycle();
157160
void generate_pomodoros();
158161
void show_task();
162+
163+
void notify(const char *icon, const char *message);
159164
void notify(const char *message);
165+
void notify_with_green_icon(const char *message);
166+
void notify_with_gray_icon(const char *message);
167+
160168
Task* get_current_task();
161169
void inc_current_task();
162170
void execute(string script);
@@ -165,6 +173,7 @@ class WinMain: public Gtk::Window
165173
Glib::ustring get_current_list();
166174
void update_positions();
167175
void move_task(string list);
176+
void set_systray();
168177

169178
void show_task_buttons();
170179
void hide_task_buttons();

0 commit comments

Comments
 (0)