-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.c
3224 lines (2844 loc) · 93.5 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* GTimer
*
* Copyright:
* (C) 1999-2023 Craig Knudsen, [email protected]
* See accompanying file "COPYING".
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307, USA
*
* Description:
* Helps you keep track of time spent on different tasks.
*
* Author:
* Craig Knudsen, [email protected], http://www.k5n.us
*
* Home Page:
* https://www.k5n.us/gtimer/
*
* History:
* 07-Aug-2008 Ver 1.1.7 - Support UTF-8 using GTK+ ver. > 2.4.0
* 15-Jul-2005 Add -weekstart to configure the first day of the
* week. (Russ Allbery)
* 31-May-2005 When exiting, only change the window size
* configuration if gdk_window_get_size succeeds.
* (Russ Allbery)
* 18-Apr-2005 Fully stop timing and update the icons properly
* after a reset from the idle window.
* Subtract off the five minute initial period when
* reverting after an idle. (Russ Allbery)
* 17-Apr-2005 Added configurability of the browser. (Russ Allbery)
* 02-Jan-2004 Add time increment and decrement by one minute.
* Add more key shortcuts for increment/decrement.
* 64-bit fixes for time changes. (Klaus Ethgen)
* 02-Jan-2004 Add a callback to clear the paste buffer. (Klaus
* Ethgen)
* 13-Mar-2003 Added cut/copy/paste in new Edit menu.
* 06-Mar-2003 Added support for -resume option which will start
* timing the same task that was being timed last
* time gtimer exited.
* 01-Mar-2003 Added projects
* 09-Mar-2000 Improved idle handling. On revert, the tasks are
* no longer reloaded from the data files and the
* display will not be resorted.
* Added a "resume" option for idles that continues
* timing but throws out all the idle time.
* 21-May-1999 Moved around menu (added tools and help)
* 19-May-1999 Added ability to check for new version.
* This is a really COOL feature :-)
* 13-May-1999 Allow users to view ChangeLog.
* 13-May-1999 Added handle box to menu.
* 04-May-1999 Oops. Fixed label that said "inc 5 seconds" to
* say "inc 5 minutes".
* 30-Apr-1999 Added support help options: -h, -help, --help
* 30-Apr-1999 Added support version options: -v, -version, --version
* 30-Apr-1999 Added support for -start option.
* 25-Mar-1999 Made animated clock in clist optional.
* 25-Mar-1999 Applied some WIN32 patches provided by
* Thomas Epperly <[email protected]>
* 25-Mar-1999 Fixed bug where -nosplash would cause the main window
* to not remember the correct window size.
* 25-Mar-1999 Fixed bugs when using start/stop/etc. before any
* tasks have been created.
* 24-Mar-1999 Made toolbar optional
* 24-Mar-1999 Added tearoff menus
* 18-Mar-1999 Internationalization
* 18-Mar-1999 Added support for X11 screen saver extension
* for idle detect. (This will detect keyboard
* usage rather than just mouse usage.)
* 16-Mar-1999 Added back in support for GTK 1.0 via autoconf.
* (Stole some of the autoconf stuff from xhippo-0.7.)
* GTK 1.1/1.2 handles clist double-click events
* completely different than GTK 1.0.
* 24-Feb-1999 Added unhide function (finally... have had the
* hide function for a while now.)
* 11-Feb-1999 Modified accelerator key code.
* Fixed to have task pulldown menu with right mouse
* button (API changed from GTK+1.0)
* 08-Feb-1999 Added changes for accelerator keys provided by
* Matt Martin <[email protected]>
* 02-Feb-1999 Remember main window width & height
* 21-Jan-1999 Added gtk-1.1 support (received patches from
* Stephen Webb & Jim Bray).
* 11-Nov-1998 Added support for hiding tasks
* 13-Jul-1998 Make double-click stop timing all other tasks and
* start timing the selected task.
* 09-May-1998 Added autosave option
* 07-May-1998 Finished idle detect option
* 08-Apr-1998 Set the application icon within the application.
* Display a different icon depening on whether or not
* we are timing any tasks.
* 06-Apr-1998 Began adding code for idle detect
* 05-Apr-1998 Fixed vertical resize (status was resizing)
* code submitted by Zach Beane ([email protected])
* 05-Apr-1998 Added splash screen.
* 01-Apr-1998 Added status bar and total hours for today at
* the bottom of the main window.
* 18-Mar-1998 Reduce flicker in task list when changing sort
* code submitted by Zach Beane ([email protected])
* 18-Mar-1998 Release 0.95
* 18-Mar-1998 Added calls to gtk_window_set_wmclass so the windows
* behave better for window managers.
* code submitted by ObiTuarY ([email protected])
* 17-Mar-1998 Fixed handing if $HOME is not defined.
* 16-Mar-1998 Changed name to "GTimer"
* updated application icon
* 15-Mar-1998 Added memory debugging calls (memdebug.h).
* (The memdebug library is something I wrote myself
* a few years ago for another project. It keeps
* track of all malloc/realloc/free calls and can
* show you what's been allocated but not freed with
* the md_print_all () function. Email me if you
* would like this library.)
* 15-Mar-1998 Added annotate icon and ability to add annotations
* (dated comments) to tasks.
* 13-Mar-1998 Click on column header to sort by that column.
* 13-Mar-1998 Did some code redesign. Pulldown menus setup
* from the TTPulldown structure.
* 13-Mar-1998 Add pulldown menu for right mouse click on a task.
* Added functions to add time and remove time from
* a task.
* 13-Mar-1998 Add pulldown menu for right mouse click on a task.
* code submitted by Zach Beane ([email protected])
* 13-Mar-1998 Double-click on a task brings up the edit window
* code submitted by Zach Beane ([email protected])
* 13-Mar-1998 Fixed handling of date change when time passes
* midnight.
* 11-Mar-1998 Rearranged UI. Added toolbar with icons.
* Added "Report" to menubar.
* 25-Feb-1998 Created
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <pwd.h>
#include <time.h>
#include <memory.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
#include <gtk/gtk.h>
#ifdef HAVE_APP_INDICATOR
#include <libappindicator/app-indicator.h>
#endif
#ifdef HAVE_SCREEN_SAVER_EXT
#include <gdk/gdkx.h>
#endif
#include "project.h"
#include "task.h"
#include "gtimer.h"
#include "gtimeri18n.h"
#include "config.h"
#include "tcpt.h"
#include "http.h"
// PV:
#include "custom-list.h"
#ifdef GTIMER_MEMDEBUG
#include "memdebug/memdebug.h"
#endif
/* check for a new version every 30 days */
#define VERSION_CHECK_INTERVAL (3600 * 24 * 30)
/* splash icon */
#include "icons/splash.xpm"
/* app icons */
#include "icons/gtimer.xpm"
#include "icons/gtimer2.xpm"
/* timer icon */
#include "icons/clock1.xpm"
#include "icons/clock2.xpm"
#include "icons/clock3.xpm"
#include "icons/clock4.xpm"
#include "icons/clock5.xpm"
#include "icons/clock6.xpm"
#include "icons/clock7.xpm"
#include "icons/clock8.xpm"
#include "icons/blank.xpm"
/* toolbar icons */
#include "icons/start.xpm"
#include "icons/stop.xpm"
#include "icons/stop_all.xpm"
#include "icons/annotate.xpm"
#include "icons/new.xpm"
#include "icons/edit.xpm"
GtkWidget *main_window = NULL;
static GtkWidget *splash_window = NULL;
static int move_to_task = -1;
static GtkWidget *idle_prompt_window = NULL;
static GtkWidget *option_menu_items[4];
static time_t splash_until, last_save;
static int modified_since_save = 0;
static int splash_seconds = 2;
GtkWidget *toolbar = NULL;
GtkWidget *task_list = NULL;
GtkWidget *status = NULL;
guint status_id = 0;
static time_t lastMessageTime = 0;
GtkWidget *total_label = NULL;
static char total_str[20];
GdkPixmap *icons[8], *blankicon, *appicon, *appicon2;
GdkBitmap *icon_masks[8], *blankicon_mask, *appicon_mask, *appicon2_mask;
#if OLD_GTK
#else
GtkAccelGroup* mainag;
#endif
#ifdef HAVE_APP_INDICATOR
static AppIndicator *indicator;
#endif
static sockfd connection = -1;
static gint gdk_input_id = -1;
static int version_check_is_auto = 0;
static int cutBuffer = 0; /* Seconds from cut/copy/set-to-zero/revert/resume*/
static int messageDisplayTime = 15; /* how long to leave messages up */
typedef struct {
char *name;
int width;
int max_width;
GtkJustification justify;
gboolean resizeable;
GtkWidget *widget;
} list_column_def;
static int sort_forward = 1;
static int last_sort = 0;
static int rebuilding_list = 0;
int today_year, today_mon, today_mday;
int config_midnight_offset = 0;
int config_max_idle = 0;
int config_idle_enabled = 0;
int config_autosave_enabled = 1;
int config_toolbar_enabled = 1;
int config_animate_enabled = 1;
int config_autosave_interval = (60*15); /* 15 minutes */
int config_start_of_week = 0;
char *taskdir = NULL;
char *config_file = NULL;
char *gtkrc = NULL;
int selected_task = -1;
int pulldown_selected_task = -1; /* task selected with right mouse button */
TaskData **tasks;
int num_tasks = 0;
int num_timing = 0;
TaskData **visible_tasks; /* not hidden */
int num_visible_tasks;
list_column_def task_list_columns[4] = {
{ "Project", 150, 0, GTK_JUSTIFY_LEFT, (gboolean)1, NULL },
{ "Task", 150, 0, GTK_JUSTIFY_LEFT, (gboolean)1, NULL },
{ "Today", 70, 70, GTK_JUSTIFY_RIGHT, (gboolean)0, NULL },
{ "Total", 70, 70, GTK_JUSTIFY_RIGHT, (gboolean)0, NULL }
};
/*
** Local functions
*/
void update_list ();
static void build_list ();
static void about_callback ( GtkAction *act );
static void website_callback ( GtkAction *act );
static void changelog_callback ( GtkAction *act );
static void save_callback ( GtkAction *act );
static void exit_callback ( GtkAction *act );
static void start_callback ( GtkAction *act );
static void switch_to_callback ( GtkWidget *widget, gpointer data );
static void stop_callback ( GtkAction *act );
static void stop_all_callback ( GtkAction *act );
static void task_add_callback ( GtkAction *act );
static void task_edit_callback ( GtkAction *act );
static void task_hide_callback ( GtkAction *act );
static void task_unhide_callback ( GtkAction *act );
static void task_delete_callback ( GtkAction *act );
static void task_cut_callback ( GtkAction *act );
static void task_copy_callback ( GtkAction *act );
static void task_paste_callback ( GtkAction *act );
static void task_clear_callback ( GtkAction *act );
static void increment_time_callback ( GtkWidget *widget, gpointer data );
static void decrement_time_callback ( GtkWidget *widget, gpointer data );
static void project_add_callback ( GtkAction *act );
static void project_edit_callback ( GtkAction *act );
//static void report_callback ( GtkWidget *widget, gpointer data );
static void annotate_callback ( GtkAction *act );
static void idle_reset_callback ( GtkWidget *widget, gpointer data );
static void idle_cancel_callback ( GtkWidget *widget, gpointer data );
static void idle_resume_callback ( GtkWidget *widget, gpointer data );
static void column_selected_callback ( GtkWidget *widget, int col );
static void toolbar_toggle_callback ( GtkToggleAction *act );
static void idle_toggle_callback ( GtkToggleAction *act );
static void autosave_toggle_callback ( GtkToggleAction *act );
static void animate_toggle_callback ( GtkToggleAction *act );
static void check_version_callback ( GtkAction *act );
static void set_browser_callback ( GtkAction *act );
// PV:
static void shift_time_callback ( GtkAction *act );
static void report2_callback ( GtkAction *act );
/*
** Structure for defining the the pulldown menus.
*/
typedef struct {
int label_index;
void (*callback)();
gpointer data;
gint acckey;
GdkModifierType accmod;
} TTPulldown;
// PV: move main menu to GtkActionEntry Structures (see GTK+ Reference Manual,
// Example 55 - 59)
// globally accessible UI Manager object
GtkUIManager *uimanager;
// Menu Entries - because it is neccessary to translate each menu item as separate word, I decide
// to assign unique prefix to each menu column and merge these prefixes to menu items.
// Prefix will be hidden during translation (see function mainmenu_translate).
// Last character in prefix is '|', I hope this character never appears as a part of displayed word.
// If I'll not be right in future, please change it to another character in menu and function
// mainmenu_translate.
// Recommendation: It will be better _do_not_translate_ these prefixes.
static const GtkActionEntry MM_NormalEntries[] = {
{ "FileMenu", NULL, gettext_noop("MM|_File") },
{ "EditMenu", NULL, gettext_noop("MM|_Edit") },
{ "OptionsMenu", NULL, gettext_noop("MM|_Options") },
{ "TaskMenu", NULL, gettext_noop( "MM|_Task") },
{ "ProjectMenu", NULL, gettext_noop("MM|_Project") },
{ "ReportMenu", NULL, gettext_noop("MM|_Report") },
/*
{ "ToolsMenu", NULL, gettext_noop("MM|_Tools") },
*/
{ "HelpMenu", NULL, gettext_noop("MM|_Help") },
{ "FM_Save", GTK_STOCK_SAVE, gettext_noop("FM|_Save"), "<control>S",
gettext_noop("Save actual state"), G_CALLBACK(save_callback) },
{ "FM_Exit", GTK_STOCK_QUIT, gettext_noop("FM|_Exit"), "<control>Q",
gettext_noop("Exit program"), G_CALLBACK(exit_callback) },
{ "EM_Cut", GTK_STOCK_CUT, gettext_noop("EM|C_ut Time"), "<control>X",
gettext_noop("Cut actual time from line to buffer"), G_CALLBACK(task_cut_callback) },
{ "EM_Copy", GTK_STOCK_COPY, gettext_noop("EM|_Copy Time"), "<control>C",
gettext_noop("Copy actual time from line to buffer"), G_CALLBACK(task_copy_callback) },
{ "EM_Paste", GTK_STOCK_PASTE, gettext_noop("EM|_Paste Time"), "<control>V",
gettext_noop("Paste actual time from buffer to actual line"), G_CALLBACK(task_paste_callback) },
{ "EM_Clear", GTK_STOCK_CLEAR, gettext_noop("EM|Clear _Buffer"), NULL,
gettext_noop("Clear buffer"), G_CALLBACK(task_clear_callback) },
{ "OM_Browser", NULL, gettext_noop("OM|_Browser ..."), NULL,
gettext_noop("Set your preferred web browser"), G_CALLBACK(set_browser_callback) },
{ "TM_Start", NULL, gettext_noop("TM|_Start Timing"), "<alt>S",
gettext_noop("Start timing of selected task"), G_CALLBACK(start_callback) },
{ "TM_Stop", NULL, gettext_noop("TM|S_top Timing"), "<alt>X",
gettext_noop("Stop timing of selected task"), G_CALLBACK(stop_callback) },
{ "TM_Stopall", NULL, gettext_noop("TM|Stop A_ll Timing"), "<alt>T",
gettext_noop("Stop timing of all running tasks"), G_CALLBACK(stop_all_callback) },
{ "TM_New", NULL, gettext_noop("TM|_New..."), "<control>N",
gettext_noop("Create new task"), G_CALLBACK(task_add_callback) },
{ "TM_Edit", NULL, gettext_noop("TM|_Edit... "), "<control>E",
gettext_noop("Edit selected task"), G_CALLBACK(task_edit_callback) },
{ "TM_Annotate", NULL, gettext_noop("TM|_Annotate..."), "<control>A",
gettext_noop("Add annotation"), G_CALLBACK(annotate_callback) },
{ "TM_Hide", NULL, gettext_noop("TM|_Hide"), "<control>H",
gettext_noop("Hide task"), G_CALLBACK(task_hide_callback) },
{ "TM_Unhide", NULL, gettext_noop("TM|_Unhide... "), "<control>U",
gettext_noop("Unhide tasks"), G_CALLBACK(task_unhide_callback) },
{ "TM_Delete", NULL, gettext_noop("TM|_Delete"), "<control>R",
gettext_noop("Add annotation"), G_CALLBACK(task_delete_callback) },
{ "TM_Inc1", NULL, gettext_noop("TM|_Increment 1 minute"), "<shift><control>I",
gettext_noop("Increment time"), G_CALLBACK(shift_time_callback) },
{ "TM_Inc5", NULL, gettext_noop("TM|I_ncrement 5 minutes"), "<control>I",
gettext_noop("Increment time"), G_CALLBACK(shift_time_callback) },
{ "TM_Inc30", NULL, gettext_noop("TM|In_crement 30 minute"), "<control><alt>I",
gettext_noop("Increment time"), G_CALLBACK(shift_time_callback) },
{ "TM_Dec1", NULL, gettext_noop("TM|Decrement _1 minute"), "<shift><control>D",
gettext_noop("Decrement time"), G_CALLBACK(shift_time_callback) },
{ "TM_Dec5", NULL, gettext_noop("TM|Decrement _5 minutes"), "<control>D",
gettext_noop("Decrement time"), G_CALLBACK(shift_time_callback) },
{ "TM_Dec30", NULL, gettext_noop("TM|Decrement _30 minutes"), "<control><alt>D",
gettext_noop("Decrement time"), G_CALLBACK(shift_time_callback) },
{ "TM_Zero", NULL, gettext_noop("TM|Set to _Zero"), "<control><alt>0",
gettext_noop("Clear time of selected task"), G_CALLBACK(shift_time_callback) },
{ "PM_New", NULL, gettext_noop("PM|_New..."), NULL,
gettext_noop("New Project"), G_CALLBACK(project_add_callback) },
{ "PM_Edit", NULL, gettext_noop("PM|_Edit..."), NULL,
gettext_noop("Edit Project"), G_CALLBACK(project_edit_callback) },
{ "RM_Daily", NULL, gettext_noop("RM|_Daily..."), NULL,
gettext_noop("Daily Report"), G_CALLBACK(report2_callback) },
{ "RM_Weekly", NULL, gettext_noop("RM|_Weekly..."), NULL,
gettext_noop("Weekly Report"), G_CALLBACK(report2_callback) },
{ "RM_Monthly", NULL, gettext_noop("RM|_Monthly..."), NULL,
gettext_noop("Monthly Report"), G_CALLBACK(report2_callback) },
{ "RM_Yearly", NULL, gettext_noop("RM|_Yearly..."), NULL,
gettext_noop("Yearly Report"), G_CALLBACK(report2_callback) },
/*
{ "TL_Check", NULL, gettext_noop("TL|_Check for New Version..."), NULL,
gettext_noop("Keep your program updated"), G_CALLBACK(check_version_callback) },
*/
{ "HM_About", NULL, gettext_noop("HM|_About..."), NULL,
gettext_noop("About"), G_CALLBACK(about_callback) },
{ "HM_ViewChL", NULL, gettext_noop("HM|View _Change log..."), NULL,
gettext_noop("Changelog"), G_CALLBACK(changelog_callback) },
{ "HM_VisitWeb", NULL, gettext_noop("HM|Visit _Website..."), NULL,
gettext_noop("Open web browser"), G_CALLBACK(website_callback) }
};
/* PV: Add Toggle Entries
* This structure is initialized with FALSE initial values. Before activating it will
* be modified according to configuration settings. This is why this structure is not
* declared as 'const'
*/
//static const GtkToggleActionEntry MM_ToggleEntries[] = {
static GtkToggleActionEntry MM_ToggleEntries[] = {
{ "OM_Toolbar", NULL, gettext_noop("OM|_Toolbar"), NULL,
NULL, G_CALLBACK(toolbar_toggle_callback), FALSE },
{ "OM_Animate", NULL, gettext_noop("OM|_Animate"), NULL,
NULL, G_CALLBACK(animate_toggle_callback), FALSE },
{ "OM_Idle", NULL, gettext_noop("OM|_Idle Detect"), NULL,
NULL, G_CALLBACK(idle_toggle_callback), FALSE },
{ "OM_Autosave", NULL, gettext_noop("OM|Auto _Save"), NULL,
NULL, G_CALLBACK(autosave_toggle_callback), FALSE },
};
// according to MM_ToggleEntries set following constants:
#define MM_TOGGLE_TOOLBAR 0
#define MM_TOGGLE_ANIMATE 1
#define MM_TOGGLE_IDLE 2
#define MM_TOGGLE_AUTOSAVE 3
//PV: XML description:
static const char * menustring =
"<ui>"
" <menubar name='MainMenu'>"
" <menu action='FileMenu'>"
" <menuitem action='FM_Save'/>"
" <separator/>"
" <menuitem action='FM_Exit'/>"
" </menu>"
" <menu action='EditMenu'>"
" <menuitem action='EM_Cut'/>"
" <menuitem action='EM_Copy'/>"
" <menuitem action='EM_Paste'/>"
" <menuitem action='EM_Clear'/>"
" </menu>"
" <menu action='OptionsMenu'>"
" <menuitem action='OM_Toolbar'/>"
" <menuitem action='OM_Animate'/>"
" <menuitem action='OM_Idle'/>"
" <menuitem action='OM_Autosave'/>"
" <menuitem action='OM_Browser'/>"
" </menu>"
" <menu action='TaskMenu'>"
" <menuitem action='TM_Start'/>"
" <menuitem action='TM_Stop'/>"
" <menuitem action='TM_Stopall'/>"
" <separator/>"
" <menuitem action='TM_New'/>"
" <menuitem action='TM_Edit'/>"
" <menuitem action='TM_Annotate'/>"
" <menuitem action='TM_Hide'/>"
" <menuitem action='TM_Unhide'/>"
" <menuitem action='TM_Delete'/>"
" <separator/>"
" <menuitem action='TM_Inc1'/>"
" <menuitem action='TM_Inc5'/>"
" <menuitem action='TM_Inc30'/>"
" <menuitem action='TM_Dec1'/>"
" <menuitem action='TM_Dec5'/>"
" <menuitem action='TM_Dec30'/>"
" <menuitem action='TM_Zero'/>"
" </menu>"
" <menu action='ProjectMenu'>"
" <menuitem action='PM_New'/>"
" <menuitem action='PM_Edit'/>"
" </menu>"
" <menu action='ReportMenu'>"
" <menuitem action='RM_Daily'/>"
" <menuitem action='RM_Weekly'/>"
" <menuitem action='RM_Monthly'/>"
" <menuitem action='RM_Yearly'/>"
" </menu>"
" <menu action='ToolsMenu'>"
" <menuitem action='TL_Check'/>"
" </menu>"
" <separator/>"
" <menu action='HelpMenu'>"
" <menuitem action='HM_About'/>"
" <menuitem action='HM_ViewChL'/>"
" <menuitem action='HM_VisitWeb'/>"
" </menu>"
" </menubar>"
" <popup name='PopupMenu'>"
" <menuitem action='TM_Start'/>"
" <menuitem action='TM_Stop'/>"
" <menuitem action='TM_Stopall'/>"
" <separator/>"
" <menuitem action='TM_New'/>"
" <menuitem action='TM_Edit'/>"
" <menuitem action='TM_Annotate'/>"
" <menuitem action='TM_Hide'/>"
" <menuitem action='TM_Unhide'/>"
" <menuitem action='TM_Delete'/>"
" <separator/>"
" <menuitem action='TM_Inc1'/>"
" <menuitem action='TM_Inc5'/>"
" <menuitem action='TM_Inc30'/>"
" <menuitem action='TM_Dec1'/>"
" <menuitem action='TM_Dec5'/>"
" <menuitem action='TM_Dec30'/>"
" <menuitem action='TM_Zero'/>"
" </popup>"
"</ui>";
/*
** Structure for defining the toolbar
*/
// PV: Move it to UI manager too? Later ...
typedef struct {
char *label;
char *tooltip_index;
gchar **icon_data;
void (*callback)();
GtkWidget *widget;
gpointer data;
} TTToolButton;
#define TOOLBAR_START_BUTTON 0
#define TOOLBAR_STOP_BUTTON 1
#define TOOLBAR_STOP_ALL_BUTTON 2
TTToolButton main_toolbar[] = {
{ gettext_noop("Start"),
gettext_noop("Start Timing the Selected Task"),
start_xpm,
start_callback, NULL, NULL },
{ gettext_noop("Stop"),
gettext_noop("Stop Timing the Selected Task"),
stop_xpm,
stop_callback, NULL, NULL },
{ gettext_noop("Stop All"),
gettext_noop("Stop Timing All Tasks"),
stop_all_xpm,
stop_all_callback, NULL, NULL },
{ gettext_noop("Annotate"),
gettext_noop("Add Annotation to Selected Task"),
annotate_xpm,
annotate_callback, NULL, NULL },
{ gettext_noop("Add"),
gettext_noop("Add New Task"),
new_xpm,
task_add_callback, NULL, NULL },
{ gettext_noop("Edit"),
gettext_noop("Edit Name of the Selected Task") ,
edit_xpm,
task_edit_callback, NULL, NULL },
{ NULL, 0, NULL, NULL, NULL, NULL }
};
#ifdef WIN32
static void convert_backslash ( filename )
char *filename;
{
while ( *filename ){
if ( *filename == '\\' )
*filename = '/';
filename++;
}
}
#endif
/*
** Get the currently selected task. If the user has used the right mouse
** button to create a pulldown menu, then pulldown_selected_task will
** be set. This routine should called only once per callback since
** we reset the value of pulldown_selected_task.
*/
static int get_selected_task ()
{
int ret;
if ( pulldown_selected_task >= 0 ) {
ret = pulldown_selected_task;
pulldown_selected_task = -1;
} else
ret = selected_task;
return ret;
}
static int my_strcasecmp ( char *str1, char *str2 )
{
char *ptr1, *ptr2, *ptr;
int ret;
ptr1 = strdup ( str1 );
ptr2 = strdup ( str2 );
for ( ptr = ptr1; *ptr != '\0'; ptr++ ) {
*ptr = toupper ( *ptr );
}
for ( ptr = ptr2; *ptr != '\0'; ptr++ ) {
*ptr = toupper ( *ptr );
}
ret = strcmp ( ptr1, ptr2 );
free ( ptr1 );
free ( ptr2 );
return ( ret );
}
/*
* Sort by project id, which will put oldest projects first, newest
* projects last.
*/
static int sort_task_by_project_id ( td1, td2 )
TaskData **td1;
TaskData **td2;
{
TaskData *tda = *td1;
TaskData *tdb = *td2;
int ret;
/* put tasks with no projects (-1) at the end of the list, most
recent projects at the top */
if ( tda->task->project_id > tdb->task->project_id )
ret = -1;
else if ( tda->task->project_id < tdb->task->project_id )
ret = 1;
else
ret = 0;
if ( sort_forward )
return ( ret );
else
return ( - ret );
}
/*
* Sort by project name.
*/
static int sort_task_by_project_name ( td1, td2 )
TaskData **td1;
TaskData **td2;
{
TaskData *tda = *td1;
TaskData *tdb = *td2;
int ret;
/* put tasks with no projects (-1) at the end of the list, most
recent projects at the top */
if ( tda->task->project_id < 0 )
ret = -1;
else if ( tdb->task->project_id < 0 )
ret = 1;
else
ret = my_strcasecmp ( tda->project_name, tdb->project_name );
if ( sort_forward )
return ( ret );
else
return ( - ret );
}
static int sort_task_by_name ( td1, td2 )
TaskData **td1;
TaskData **td2;
{
TaskData *tda = *td1;
TaskData *tdb = *td2;
int ret;
ret = ( my_strcasecmp ( tda->task->name, tdb->task->name ) );
if ( sort_forward )
return ( ret );
else
return ( - ret );
}
static int sort_task_by_id ( td1, td2 )
TaskData **td1;
TaskData **td2;
{
TaskData *tda = *td1;
TaskData *tdb = *td2;
int ret;
/* put most recent tasks at the top */
if ( tda->task->number > tdb->task->number )
ret = -1;
else if ( tda->task->number < tdb->task->number )
ret = 1;
else
ret = 0;
if ( sort_forward )
return ( ret );
else
return ( - ret );
}
static int sort_task_by_today ( td1, td2 )
TaskData **td1;
TaskData **td2;
{
TaskData *tda = *td1;
TaskData *tdb = *td2;
int ret = 0;
if ( tda->last_today_int > tdb->last_today_int )
ret = 1;
else if ( tda->last_today_int < tdb->last_today_int )
ret = -1;
else if ( tda->last_today_int == tdb->last_today_int )
ret = ( (void *)tda < (void *)td2 );
if ( sort_forward )
return ( - ret );
else
return ( ret );
}
static int sort_task_by_total ( td1, td2 )
TaskData **td1;
TaskData **td2;
{
TaskData *tda = *td1;
TaskData *tdb = *td2;
int ret = 0;
if ( tda->last_total_int > tdb->last_total_int )
ret = 1;
else if ( tda->last_total_int < tdb->last_total_int )
ret = -1;
else if ( tda->last_total_int == tdb->last_total_int )
ret = ( (void *)tda < (void *)td2 );
if ( sort_forward )
return ( - ret );
else
return ( ret );
}
/*
** Transfer all the time for tasks currently being timed into the
** Task data structure so the reports will have access to it easily.
*/
static void update_tasks ()
{
int i;
time_t now, diff;
time ( &now );
for ( i = 0; i < num_visible_tasks; i++ ) {
if ( visible_tasks[i]->timer_on ) {
diff = now - visible_tasks[i]->on_since;
visible_tasks[i]->todays_entry->seconds += diff;
visible_tasks[i]->on_since = now;
}
}
}
/*
** Save all the tasks to their files.
*/
void save_all ()
{
update_tasks ();
taskSaveAll ( taskdir );
projectSaveAll ( taskdir );
time ( &last_save );
modified_since_save = 0;
}
/* Delete window handler */
gint delete_event ( widget, event, data )
GtkWidget *widget;
GdkEvent *event;
gpointer data;
{
save_all ();
configSaveAttributes ( config_file );
#ifdef GTIMER_MEMDEBUG
configClear ();
#endif
return ( TRUE );
}
static void exit_callback ( GtkAction *act )
{
gint w, h;
char temp[128];
int loop;
/* save task data */
save_all ();
/* save window size */
w = 0;
h = 0;
gdk_window_get_size ( GTK_WIDGET ( main_window )->window, &w, &h );
if ( w != 0 && h != 0 ) {
configSetAttributeInt ( CONFIG_MAIN_WINDOW_WIDTH, w );
configSetAttributeInt ( CONFIG_MAIN_WINDOW_HEIGHT, h );
}
/* get columns widths in main window */
w = GTK_CLIST ( task_list )->column[0].width;
configSetAttributeInt ( CONFIG_MAIN_WINDOW_PROJECT_WIDTH, w );
w = GTK_CLIST ( task_list )->column[1].width;
configSetAttributeInt ( CONFIG_MAIN_WINDOW_TASK_WIDTH, w );
w = GTK_CLIST ( task_list )->column[2].width;
configSetAttributeInt ( CONFIG_MAIN_WINDOW_TODAY_WIDTH, w );
w = GTK_CLIST ( task_list )->column[3].width;
configSetAttributeInt ( CONFIG_MAIN_WINDOW_TOTAL_WIDTH, w );
/* keep track of which tasks were being timed in case the user starts up
with -resume next time */
temp[0] = '\0';
for ( loop = 0; loop < num_visible_tasks; loop++ ) {
if ( visible_tasks[loop]->timer_on ) {
if ( strlen ( temp ) )
strcat ( temp, "," );
sprintf ( temp + strlen ( temp ), "%d",
visible_tasks[loop]->task->number );
}
}
configSetAttribute ( CONFIG_LAST_TIMED_TASKS, temp );
/* save config settings */
configSaveAttributes ( config_file );
#ifdef GTIMER_MEMDEBUG
free ( config_file );
configClear ();
#endif
gtk_main_quit ();
}
/*
** Set toolbar buttons to sensitive/insensitive based
** on our current status.
*/
static void update_toolbar_buttons () {
if ( num_timing ) {
gtk_widget_set_sensitive (
GTK_WIDGET ( main_toolbar[TOOLBAR_STOP_BUTTON].widget ), 1 );
gtk_widget_set_sensitive (
GTK_WIDGET ( main_toolbar[TOOLBAR_STOP_ALL_BUTTON].widget ), 1 );
} else {
gtk_widget_set_sensitive (
GTK_WIDGET ( main_toolbar[TOOLBAR_STOP_BUTTON].widget ), 0 );
gtk_widget_set_sensitive (
GTK_WIDGET ( main_toolbar[TOOLBAR_STOP_ALL_BUTTON].widget ), 0 );
}
if ( num_visible_tasks ) {
gtk_widget_set_sensitive (
GTK_WIDGET ( main_toolbar[TOOLBAR_START_BUTTON].widget ), 1 );
} else {
gtk_widget_set_sensitive (
GTK_WIDGET ( main_toolbar[TOOLBAR_START_BUTTON].widget ), 0 );
}
}
static void save_callback ( GtkAction *act )
{
showMessage ( gettext("All data saved") );
save_all ();
}
static void about_callback ( GtkAction *act )
{
char text[1024];
sprintf ( text,
"GTimer\n%s\n%s: %s (%s)\n%s\nGTK %s: %d.%d.%d\n\n",
GTIMER_COPYRIGHT, gettext("Version"), GTIMER_VERSION, GTIMER_VERSION_DATE,
GTIMER_URL, gettext("Version"),
gtk_major_version, gtk_minor_version, gtk_micro_version );
strcat ( text, gettext("Author") );
sprintf ( text + strlen ( text ),
":\nCraig Knudsen\[email protected]\n\n" );
create_confirm_window ( CONFIRM_ABOUT,
gettext("About"),
text,
gettext("Ok"), NULL, NULL, NULL, NULL, NULL, NULL );
}
static void changelog_callback ( GtkAction *act )
{
display_changelog ();
}
static void website_callback ( GtkAction *act )
{
char *path, *command;
if ( configGetAttribute ( CONFIG_BROWSER, &path ) < 0 )
path = "mozilla";
command = (char *) malloc ( strlen ( path ) + 128 );
if ( strstr ( path, "%s" ) )
sprintf ( command, path, GTIMER_URL );
else
sprintf ( command, "%s %s", path, GTIMER_URL );
if ( system ( command ) != 0 ) {
create_confirm_window ( CONFIRM_ERROR,
gettext("Error"), gettext("Error communicating with browser."),
gettext("Ok"), NULL, NULL,
NULL, NULL, NULL, NULL );
}
free ( command );
}
static void task_add_callback ( GtkAction *act )
{
create_task_edit_window ( NULL );
}
static void task_edit_callback ( GtkAction *act )
{
int st = get_selected_task ();
if ( st < 0 || ! num_visible_tasks ) {
create_confirm_window ( CONFIRM_ERROR,
gettext("Error"),
gettext("You have not selected\na task to edit."),
gettext("Ok"), NULL, NULL,
NULL, NULL, NULL,
NULL );
} else {
create_task_edit_window ( visible_tasks[st] );
}
}
static void task_hide_callback ( GtkAction *act )
{
TaskData *td;
int i, st;
st = get_selected_task ();
if ( st < 0 || ! num_visible_tasks ) {
create_confirm_window ( CONFIRM_ERROR,