-
Notifications
You must be signed in to change notification settings - Fork 2
/
dsbmc.c
2363 lines (2189 loc) · 68.5 KB
/
dsbmc.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
/*-
* Copyright (c) 2016 Marcel Kaiser. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <err.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/select.h>
#include <sys/file.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <paths.h>
#include <limits.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>
#include "dsbcfg/dsbcfg.h"
#include "gtk-helper/gtk-helper.h"
#define PROGRAM "dsbmc"
#define PATH_CONFIG "config"
#define TITLE "DSBMC"
#define PATH_BOOKMARK ".gtk-bookmarks"
#define PATH_DSBMD_SOCKET "/var/run/dsbmd.socket"
#define PATH_LOCK ".dsbmc.lock"
#define CMDQSZ 16
#define LABEL_WIDTH 16
#define CDR_MAXSPEED 52
#define ICON_LOOKUP_FLAGS \
(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_GENERIC_FALLBACK)
#define MARKUP_BOLD "<span font_weight=\"bold\" " \
"underline=\"single\">%s</span>"
#define MARKUP_NORMAL "<span font_weight=\"normal\">%s</span>"
#define EJECT_BUSY_MSG \
"The device is busy. Try to terminate all applications which are " \
"currently accessing the device or files on the mounted " \
"filesystem.\n\n<span font_weight=\"bold\">Shall I force " \
"ejecting the media?</span>"
#define UNMOUNT_BUSY_MSG \
"The device is busy. Try to terminate all applications which are " \
"currently accessing the device or files on the mounted " \
"filesystem.\n\n<span font_weight=\"bold\">Shall I force " \
"unmounting the device?</span>"
#define SETTINGS_MENU_INFO_MSG \
"<span font=\"monospace\" font_weight=\"bold\">%%d</span> " \
"will be replaced by the device name.\n" \
"<span font=\"monospace\" font_weight=\"bold\">%%m</span> " \
"will be replaced by the mount point."
#define BUSYWIN_MSG _("Please wait ... ")
typedef struct icon_s icon_t;
typedef struct drive_s drive_t;
typedef struct ctxmenu_s ctxmenu_t;
static int process_event(char *);
static int parse_dsbmdevent(char *);
static int create_mddev(const char *);
static char *readln(bool);
static FILE *uconnect(const char *);
static void usage(void);
static void cleanup(int);
static void catch_child(int);
static void sndcmd(void (*re)(icon_t *), icon_t *,
const char *, ...);
static void exec_cmd(const char *, drive_t *);
static void create_mainwin(void);
static void hide_win(GtkWidget *);
static void tray_click(GtkStatusIcon *, gpointer);
static void popup_tray_ctxmenu(GtkStatusIcon *, guint, guint, gpointer);
static void settings_menu(void);
static void update_icons(void);
static void set_mounted(icon_t *, bool);
static void add_bookmark(const char *);
static void del_bookmark(const char *);
static void create_icon_list(void);
static void load_pixbufs(void);
static void del_drive(const char *);
static void del_icon(const char *);
static void cb_mount(GtkWidget *, gpointer);
static void cb_unmount(GtkWidget *, gpointer);
static void cb_eject(GtkWidget *, gpointer);
static void cb_speed(GtkWidget *, gpointer);
static void cb_open(GtkWidget *, gpointer);
static void cb_play(GtkWidget *, gpointer);
static void cb_size(GtkWidget *, gpointer);
static void cb_cb(GtkWidget *, gpointer);
static void process_mount_reply(icon_t *);
static void process_unmount_reply(icon_t *);
static void process_open_reply(icon_t *);
static void process_size_reply(icon_t *);
static void process_speed_reply(icon_t *);
static void process_eject_reply(icon_t *);
static void call_reply_function(void);
static void busywin(const char *msg, bool show);
static icon_t *add_icon(drive_t *);
static drive_t *add_drive(drive_t *);
static drive_t *lookupdrv(const char *);
static drive_t *lookupdrv_from_mnt(const char *);
static gboolean window_state_event(GtkWidget *, GdkEvent *, gpointer);
static gboolean readevent(GIOChannel *, GIOCondition, gpointer);
static gboolean icon_clicked(GtkWidget *, GdkEvent *, gpointer);
static GdkPixbuf *lookup_pixbuf(const char *);
static ctxmenu_t *create_ctxmenu(icon_t *);
static const char *errmsg(int);
static GtkListStore *create_icontbl(GtkListStore *);
struct drive_s {
u_int cmds; /* Supported commands. */
#define DRVCMD_MOUNT (1 << 0x00)
#define DRVCMD_UNMOUNT (1 << 0x01)
#define DRVCMD_EJECT (1 << 0x02)
#define DRVCMD_PLAY (1 << 0x03)
#define DRVCMD_OPEN (1 << 0x04)
#define DRVCMD_SPEED (1 << 0x05)
#define DRVCMD_HIDE (1 << 0x06)
char type;
#define DSKTYPE_HDD 0x01
#define DSKTYPE_USBDISK 0x02
#define DSKTYPE_DATACD 0x03
#define DSKTYPE_AUDIOCD 0x04
#define DSKTYPE_RAWCD 0x05
#define DSKTYPE_DVD 0x06
#define DSKTYPE_VCD 0x07
#define DSKTYPE_SVCD 0x08
#define DSKTYPE_FLOPPY 0x09
#define DSKTYPE_MMC 0x0a
#define DSKTYPE_PTP 0x0b
#define DSKTYPE_MTP 0x0c
int speed;
char *dev; /* Device name */
char *volid; /* Volume ID */
char *mntpt; /* Mount point */
char *fsname; /* Filesystem name */
bool mounted; /* Whether drive is mounted. */
};
struct dsbmdevent_s {
char type; /* Event type. */
#define EVENT_SUCCESS_MSG 'O'
#define EVENT_WARNING_MSG 'W'
#define EVENT_ERROR_MSG 'E'
#define EVENT_MOUNT 'M'
#define EVENT_UNMOUNT 'U'
#define EVENT_SHUTDOWN 'S'
#define EVENT_SPEED 'V'
#define EVENT_ADD_DEVICE '+'
#define EVENT_DEL_DEVICE '-'
char *command; /* In case of a reply, the executed command. */
int mntcmderr; /* Return code of external mount command. */
int code; /* The error code */
uint64_t mediasize; /* For "size" command. */
uint64_t free; /* "" */
uint64_t used; /* "" */
#define ERR_ALREADY_MOUNTED ((1 << 8) + 0x01)
#define ERR_PERMISSION_DENIED ((1 << 8) + 0x02)
#define ERR_NOT_MOUNTED ((1 << 8) + 0x03)
#define ERR_DEVICE_BUSY ((1 << 8) + 0x04)
#define ERR_NO_SUCH_DEVICE ((1 << 8) + 0x05)
#define ERR_MAX_CONN_REACHED ((1 << 8) + 0x06)
#define ERR_NOT_EJECTABLE ((1 << 8) + 0x07)
#define ERR_UNKNOWN_COMMAND ((1 << 8) + 0x08)
#define ERR_UNKNOWN_OPTION ((1 << 8) + 0x09)
#define ERR_SYNTAX_ERROR ((1 << 8) + 0x0a)
#define ERR_NO_MEDIA ((1 << 8) + 0x0b)
#define ERR_UNKNOWN_FILESYSTEM ((1 << 8) + 0x0c)
#define ERR_UNKNOWN_ERROR ((1 << 8) + 0x0d)
#define ERR_MNTCMD_FAILED ((1 << 8) + 0x0e)
#define ERR_INVALID_ARGUMENT ((1 << 8) + 0x0f)
#define ERR_STRING_TOO_LONG ((1 << 8) + 0x10)
#define ERR_BAD_STRING ((1 << 8) + 0x11)
#define ERR_TIMEOUT ((1 << 8) + 0x12)
#define ERR_NOT_A_FILE ((1 << 8) + 0x13)
drive_t drvinfo; /* For Add/delete/mount/unmount message. */
} dsbmdevent;
typedef union val_u val_t;
struct dsbmdkeyword_s {
const char *key;
u_char type;
#define KWTYPE_CHAR 0x01
#define KWTYPE_STRING 0x02
#define KWTYPE_COMMANDS 0x03
#define KWTYPE_INTEGER 0x04
#define KWTYPE_UINT64 0x05
#define KWTYPE_DSKTYPE 0x06
union val_u {
int *integer;
char *character;
char **string;
uint64_t *uint64;
} val;
} dsbmdkeywords[] = {
{ "+", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "-", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "O", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "E", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "M", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "U", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "V", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "S", KWTYPE_CHAR, (val_t)&dsbmdevent.type },
{ "command=", KWTYPE_STRING, (val_t)&dsbmdevent.command },
{ "dev=", KWTYPE_STRING, (val_t)&dsbmdevent.drvinfo.dev },
{ "fs=", KWTYPE_STRING, (val_t)&dsbmdevent.drvinfo.fsname },
{ "volid=", KWTYPE_STRING, (val_t)&dsbmdevent.drvinfo.volid },
{ "mntpt=", KWTYPE_STRING, (val_t)&dsbmdevent.drvinfo.mntpt },
{ "type=", KWTYPE_DSKTYPE, (val_t)&dsbmdevent.drvinfo.type },
{ "speed=", KWTYPE_INTEGER, (val_t)&dsbmdevent.drvinfo.speed },
{ "code=", KWTYPE_INTEGER, (val_t)&dsbmdevent.code },
{ "cmds=", KWTYPE_COMMANDS, (val_t)(char *)0 },
{ "mntcmderr=", KWTYPE_INTEGER, (val_t)&dsbmdevent.mntcmderr },
{ "mediasize=", KWTYPE_UINT64, (val_t)&dsbmdevent.mediasize },
{ "used=", KWTYPE_UINT64, (val_t)&dsbmdevent.used },
{ "free=", KWTYPE_UINT64, (val_t)&dsbmdevent.free }
};
#define NKEYWORDS (sizeof(dsbmdkeywords) / sizeof(struct dsbmdkeyword_s))
/*
* Struct to translate DSBMD error codes into sentences.
*/
static struct error_s {
int error;
const char *msg;
} errorcodes[] = {
{ ERR_ALREADY_MOUNTED, "Device already mounted" },
{ ERR_PERMISSION_DENIED, "Permission denied" },
{ ERR_NOT_MOUNTED, "Device not mounted" },
{ ERR_DEVICE_BUSY, "Device busy" },
{ ERR_NO_SUCH_DEVICE, "No such device" },
{ ERR_MAX_CONN_REACHED, "Maximal number of connections reached" },
{ ERR_NOT_EJECTABLE, "Media not ejectable" },
{ ERR_UNKNOWN_COMMAND, "Unknow command" },
{ ERR_UNKNOWN_OPTION, "Unknow option" },
{ ERR_SYNTAX_ERROR, "Syntax error" },
{ ERR_NO_MEDIA, "No media in drive" },
{ ERR_UNKNOWN_FILESYSTEM, "Unknown filesystem" },
{ ERR_UNKNOWN_ERROR, "Unknown error" },
{ ERR_MNTCMD_FAILED, "Mouting failed" },
{ ERR_STRING_TOO_LONG, "Command string too long" },
{ ERR_BAD_STRING, "Invalid command string" },
{ ERR_TIMEOUT, "Timeout" },
{ ERR_NOT_A_FILE, "Not a regular file" }
};
#define NERRCODES (sizeof(errorcodes) / sizeof(struct error_s))
#define NPROCS 16
static struct process_s {
int error;
#define EXIT_ENOENT 127 /* The command could not be found. */
#define EXIT_EXEC_ERR 255 /* Execution of the shell failed. */
int saved_errno; /* errno set by execl(). */
char *cmdstr; /* The command which was executed. */
pid_t pid; /* The command's PID. */
} proctbl[NPROCS];
/*
* Struct to load pixbufs for device icons and context menu items.
*/
static struct pixbuftbl_s {
const char *id;
const int iconsize;
#define ICON_SIZE_ICON 46
#define ICON_SIZE_MENU 16
GdkPixbuf *icon; /* Icons for menu and devices. */
const char *name[4]; /* Icon name with alternatives. */
} pixbuftbl[] = {
{ "MTP", ICON_SIZE_ICON, NULL, { "multimedia-player",
"drive-harddisk-usb", NULL } },
{ "PTP", ICON_SIZE_ICON, NULL, { "camera-photo",
"drive-harddisk-usb", NULL } },
{ "DVD", ICON_SIZE_ICON, NULL, { "media-optical-dvd",
"drive-optical", NULL } },
{ "DATACD", ICON_SIZE_ICON, NULL, { "media-optical-cd",
"drive-optical", NULL } },
{ "USBDISK", ICON_SIZE_ICON, NULL, { "drive-harddisk-usb",
"drive-removable-media",
"drive-harddisk", NULL } },
{ "RAWCD", ICON_SIZE_ICON, NULL, { "media-optical-cd",
"drive-optical", NULL } },
{ "AUDIOCD", ICON_SIZE_ICON, NULL, { "media-optical-audio",
"drive-optical", NULL } },
{ "VCD", ICON_SIZE_ICON, NULL, { "media-optical-cd",
"drive-optical", NULL } },
{ "SVCD", ICON_SIZE_ICON, NULL, { "media-optical-cd",
"drive-optical", NULL } },
{ "HDD", ICON_SIZE_ICON, NULL, { "drive-harddisk",
"harddrive", NULL } },
{ "MMC", ICON_SIZE_ICON, NULL, { "media-flash-sd-mmc",
"media-flash", NULL } },
{ "FLOPPY", ICON_SIZE_ICON, NULL, { "media-floppy", NULL } },
{ "mounted", ICON_SIZE_ICON, NULL, { "folder", NULL } },
{ "dvd", ICON_SIZE_MENU, NULL, { "media-optical-dvd",
"drive-optical", NULL } },
{ "cd", ICON_SIZE_MENU, NULL, { "media-optical-cd",
"drive-optical", NULL } },
{ "cdda", ICON_SIZE_MENU, NULL, { "media-optical-audio",
"drive-optical", NULL } },
{ "vcd", ICON_SIZE_MENU, NULL, { "media-optical-cd",
"drive-optical", NULL } },
{ "svcd", ICON_SIZE_MENU, NULL, { "media-optical-cd",
"drive-optical", NULL } },
{ "eject", ICON_SIZE_MENU, NULL, { "media-eject", NULL } },
{ "play", ICON_SIZE_MENU, NULL, { "media-playback-start", NULL } },
{ "open", ICON_SIZE_MENU, NULL, { "document-open", NULL } },
{ "mount", ICON_SIZE_MENU, NULL, { "go-up", NULL } },
{ "unmount", ICON_SIZE_MENU, NULL, { "go-down", NULL } },
{ "hide", ICON_SIZE_MENU, NULL, { "list-remove",
"emblem-unreadable", NULL } }
};
#define PIXBUFTBLSZ (sizeof(pixbuftbl) / sizeof(struct pixbuftbl_s))
/*
* Struct to create context menus for the device icons. The order of the
* following entries represent the order of the menu items in the context
* menu.
*/
static struct menu_commands_s {
const u_int cmd;
const char *name; /* Menu Item name. */
void (*cb)(GtkWidget *, gpointer); /* Callback function. */
} menucmds[] = {
{ DRVCMD_OPEN, "_Open", &cb_open },
{ DRVCMD_PLAY, "_Play", &cb_play },
{ DRVCMD_MOUNT, "_Mount drive", &cb_mount },
{ DRVCMD_UNMOUNT, "_Unmount drive", &cb_unmount },
{ DRVCMD_SPEED, "_Set max. CDROM speed", &cb_speed },
{ DRVCMD_EJECT, "_Eject media", &cb_eject }
};
#define NMENUCMDS (sizeof(menucmds) / sizeof(struct menu_commands_s))
/*
* Struct to assign disk type strings to disktype IDs and pixbufs.
*/
struct disktypetbl_s {
const char *name;
const u_char type;
GdkPixbuf *pix_normal;
GdkPixbuf *pix_mounted;
} disktypetbl[] = {
{ "AUDIOCD", DSKTYPE_AUDIOCD, NULL, NULL },
{ "DATACD", DSKTYPE_DATACD, NULL, NULL },
{ "RAWCD", DSKTYPE_RAWCD, NULL, NULL },
{ "USBDISK", DSKTYPE_USBDISK, NULL, NULL },
{ "FLOPPY", DSKTYPE_FLOPPY, NULL, NULL },
{ "DVD", DSKTYPE_DVD, NULL, NULL },
{ "VCD", DSKTYPE_VCD, NULL, NULL },
{ "SVCD", DSKTYPE_SVCD, NULL, NULL },
{ "HDD", DSKTYPE_HDD, NULL, NULL },
{ "MMC", DSKTYPE_MMC, NULL, NULL },
{ "PTP", DSKTYPE_PTP, NULL, NULL },
{ "MTP", DSKTYPE_MTP, NULL, NULL }
};
#define NDSKTYPES (sizeof(disktypetbl) / sizeof(struct disktypetbl_s))
/*
* Struct to assign command names to command flags/IDs and a pixbuf.
*/
struct cmdtbl_s {
const char *name;
const u_int cmd;
GdkPixbuf *pix;
} cmdtbl[] = {
{ "open", DRVCMD_OPEN, NULL },
{ "play", DRVCMD_PLAY, NULL },
{ "mount", DRVCMD_MOUNT, NULL },
{ "unmount", DRVCMD_UNMOUNT, NULL },
{ "eject", DRVCMD_EJECT, NULL },
{ "speed", DRVCMD_SPEED, NULL }
};
#define NCMDS (sizeof(cmdtbl) / sizeof(struct cmdtbl_s))
enum MenuItems {
MENU_ITEM_MOUNT,
MENU_ITEM_UNMOUNT,
NMENU_ITEMS
};
struct ctxmenu_s {
GtkWidget *menu;
GtkWidget *menuitems[NMENU_ITEMS];
};
/*
* Struct to represent a device icon.
*/
struct icon_s {
drive_t *drvp;
ctxmenu_t *ctxmenu; /* Context menu. */
GtkWidget *label; /* A pointer to the icon's label. */
GdkPixbuf *pix_mounted; /* Icon pixbuf to use when mounted */
GdkPixbuf *pix_normal; /* Icon pixbuf to use when not mounted. */
GdkPixbuf *pixbuf; /* Current icon pixbuf. */
GtkTreeIter iter;
};
enum {
COL_NAME, COL_PIXBUF, COL_ICON, NUM_COLS
};
/*
* Struct to hold all the main window's variables together.
*/
static struct mainwin_s {
int *posx; /* Window's X-position */
int *posy; /* Window's Y-position */
int *width; /* Window's width */
int *height; /* Window's height */
GtkWidget *icon_view;
GtkWidget *statusbar;
GtkWindow *win; /* Main window. */
GtkListStore *store; /* Device icon grid. */
GtkStatusIcon *tray_icon;
GdkWindowState win_state; /* Visible, hidden, etc. */
} mainwin;
/*
* Struct to create the settings menu.
*/
enum {
SETTINGS_FM, SETTINGS_DVD, SETTINGS_VCD, SETTINGS_SVCD,
SETTINGS_CDDA, SETTINGS_NCMDS
};
static struct settingsmenu_s {
char ***ignore_list;
struct settings_cmd_s {
const char *action;
char **cmdstr;
const char *iconid;
bool *autoplay;
} cmds[SETTINGS_NCMDS];
} settingsmenu = {
.cmds = {
{ "Filemanager: ", NULL, "open", NULL },
{ "Play DVDs with: ", NULL, "dvd", NULL },
{ "Play VCDs with: ", NULL, "vcd", NULL },
{ "Play SVCDs with: ", NULL, "svcd", NULL },
{ "Play Audio CDs with: ", NULL, "cdda", NULL }
}
};
/*
* Struct to define a command queue. It makes sure commands
* will be processed in the correct order. A command will only
* be executed if the previous was processed.
*/
struct command_s {
char cmd[128]; /* Command string to send to DSBMD */
void (*re)(icon_t *); /* Function to call on DSBMD reply */
icon_t *icon; /* icon/device command refers to. */
} cmdq[CMDQSZ];
/*
* Definition of config file variables and their default values.
*/
#define DEFAULT_WIDTH 300
#define DEFAULT_HEIGHT 300
#define DFLT_CMD_PLAY_CDDA DSBCFG_VAL("deadbeef all.cda")
#define DFLT_CMD_PLAY_DVD DSBCFG_VAL("vlc dvd://%d")
#define DFLT_CMD_PLAY_VCD DSBCFG_VAL("vlc vcd://%d")
#define DFLT_CMD_PLAY_SVCD DSBCFG_VAL("vlc vcd://%d")
#define DFLT_CMD_FILEMANAGER DSBCFG_VAL("thunar \"%m\"")
enum {
CFG_PLAY_CDDA, CFG_PLAY_DVD, CFG_PLAY_VCD, CFG_PLAY_SVCD,
CFG_FILEMANAGER, CFG_DVD_AUTO, CFG_VCD_AUTO, CFG_SVCD_AUTO,
CFG_CDDA_AUTO, CFG_WIDTH, CFG_HEIGHT, CFG_POS_X, CFG_POS_Y,
CFG_HIDE, CFG_NVARS
};
static dsbcfg_vardef_t vardefs[] = {
{ "win_pos_x", DSBCFG_VAR_INTEGER, CFG_POS_X, DSBCFG_VAL(0) },
{ "win_pos_y", DSBCFG_VAR_INTEGER, CFG_POS_Y, DSBCFG_VAL(0) },
{ "win_width", DSBCFG_VAR_INTEGER, CFG_WIDTH, DSBCFG_VAL(346) },
{ "win_height", DSBCFG_VAR_INTEGER, CFG_HEIGHT, DSBCFG_VAL(408) },
{ "filemanager", DSBCFG_VAR_STRING, CFG_FILEMANAGER, DFLT_CMD_FILEMANAGER },
{ "play_cdda", DSBCFG_VAR_STRING, CFG_PLAY_CDDA, DFLT_CMD_PLAY_CDDA },
{ "play_dvd", DSBCFG_VAR_STRING, CFG_PLAY_DVD, DFLT_CMD_PLAY_DVD },
{ "play_vcd", DSBCFG_VAR_STRING, CFG_PLAY_VCD, DFLT_CMD_PLAY_VCD },
{ "play_svcd", DSBCFG_VAR_STRING, CFG_PLAY_SVCD, DFLT_CMD_PLAY_SVCD },
{ "dvd_auto", DSBCFG_VAR_BOOLEAN, CFG_DVD_AUTO, DSBCFG_VAL(false) },
{ "vcd_auto", DSBCFG_VAR_BOOLEAN, CFG_VCD_AUTO, DSBCFG_VAL(false) },
{ "svcd_auto", DSBCFG_VAR_BOOLEAN, CFG_SVCD_AUTO, DSBCFG_VAL(false) },
{ "cdda_auto", DSBCFG_VAR_BOOLEAN, CFG_CDDA_AUTO, DSBCFG_VAL(false) },
{ "ignore", DSBCFG_VAR_STRINGS, CFG_HIDE, DSBCFG_VAL((char **)NULL) }
};
static int cmdqlen = 0; /* # of commands in command queue. */
static int cmdqidx = 0; /* # current command to exec. in queue */
static int nicons = 0; /* # of device icons. */
static int ndrives = 0; /* # of drives. */
static FILE *sock; /* Socket connected to dsbmd. */
static icon_t **icons = NULL; /* List of device icons. */
static drive_t **drives = NULL; /* List of drives. */
static dsbcfg_t *cfg = NULL;
static void
sndcmd(void (*re)(icon_t *), icon_t *icon, const char *cmd, ...)
{
va_list ap;
if (cmdqlen == CMDQSZ)
/* Command queue is full. Just ignore further commands. */
return;
va_start(ap, cmd);
(void)vsnprintf(cmdq[cmdqlen].cmd, sizeof(cmdq[cmdqlen].cmd), cmd, ap);
cmdq[cmdqlen].re = re;
cmdq[cmdqlen].icon = icon;
if (cmdqlen++ == 0) {
/* First command in queue. */
cmdqidx = 0;
(void)fputs(cmdq[0].cmd, sock);
}
}
int
main(int argc, char *argv[])
{
int ch, i, lockfd;
gint iotag;
char *p, *path, path_lock[PATH_MAX];
sigset_t sigmask;
GIOChannel *ioc;
struct passwd *pw;
#ifdef WITH_GETTEXT
(void)setlocale(LC_ALL, "");
(void)bindtextdomain(PROGRAM, PATH_LOCALE);
(void)textdomain(PROGRAM);
#endif
gtk_init(&argc, &argv);
mainwin.win_state = GDK_WINDOW_STATE_ABOVE;
while ((ch = getopt(argc, argv, "ih")) != -1) {
switch (ch) {
case 'i':
/* Start as tray icon. */
mainwin.win_state = GDK_WINDOW_STATE_WITHDRAWN;
break;
case '?':
case 'h':
usage();
}
}
argc -= optind;
argv += optind;
if ((pw = getpwuid(getuid())) == NULL)
xerr(NULL, EXIT_FAILURE, "getpwuid()");
/* Check if another instance is already running. */
(void)snprintf(path_lock, sizeof(path_lock), "%s/%s", pw->pw_dir,
PATH_LOCK);
endpwent();
if ((lockfd = open(path_lock, O_WRONLY | O_CREAT, 0600)) == -1)
xerr(NULL, EXIT_FAILURE, "open(%s)", path_lock);
if (flock(lockfd, LOCK_EX | LOCK_NB) == -1) {
if (errno == EWOULDBLOCK) {
while (argc--)
(void)create_mddev(argv[argc]);
exit(EXIT_SUCCESS);
}
xerr(NULL, EXIT_FAILURE, "flock(%s)", path_lock);
}
while (argc--)
(void)create_mddev(argv[argc]);
if (sock != NULL)
(void)fclose(sock);
cfg = dsbcfg_read(PROGRAM, PATH_CONFIG, vardefs, CFG_NVARS);
if (cfg == NULL && errno == ENOENT) {
cfg = dsbcfg_new(NULL, vardefs, CFG_NVARS);
if (cfg == NULL)
xerrx(NULL, EXIT_FAILURE, "%s", dsbcfg_strerror());
} else if (cfg == NULL)
xerrx(NULL, EXIT_FAILURE, "%s", dsbcfg_strerror());
mainwin.posx = &dsbcfg_getval(cfg, CFG_POS_X).integer;
mainwin.posy = &dsbcfg_getval(cfg, CFG_POS_Y).integer;
mainwin.width = &dsbcfg_getval(cfg, CFG_WIDTH).integer;
mainwin.height = &dsbcfg_getval(cfg, CFG_HEIGHT).integer;
settingsmenu.cmds[SETTINGS_FM].cmdstr =
&dsbcfg_getval(cfg, CFG_FILEMANAGER).string;
settingsmenu.cmds[SETTINGS_DVD].autoplay =
(bool *)&dsbcfg_getval(cfg, CFG_DVD_AUTO).boolean;
settingsmenu.cmds[SETTINGS_DVD].cmdstr =
&dsbcfg_getval(cfg, CFG_PLAY_DVD).string;
settingsmenu.cmds[SETTINGS_VCD].autoplay =
(bool *)&dsbcfg_getval(cfg, CFG_VCD_AUTO).boolean;
settingsmenu.cmds[SETTINGS_VCD].cmdstr =
&dsbcfg_getval(cfg, CFG_PLAY_VCD).string;
settingsmenu.cmds[SETTINGS_SVCD].autoplay =
(bool *)&dsbcfg_getval(cfg, CFG_SVCD_AUTO).boolean;
settingsmenu.cmds[SETTINGS_SVCD].cmdstr =
&dsbcfg_getval(cfg, CFG_PLAY_SVCD).string;
settingsmenu.cmds[SETTINGS_CDDA].autoplay =
(bool *)&dsbcfg_getval(cfg, CFG_CDDA_AUTO).boolean;
settingsmenu.cmds[SETTINGS_CDDA].cmdstr =
&dsbcfg_getval(cfg, CFG_PLAY_CDDA).string;
settingsmenu.ignore_list =
&dsbcfg_getval(cfg, CFG_HIDE).strings;
path = PATH_DSBMD_SOCKET;
for (i = 0; i < 10 && (sock = uconnect(path)) == NULL; i++) {
if (errno == EINTR || errno == ECONNREFUSED)
(void)sleep(1);
else
xerr(NULL, EXIT_FAILURE, "Couldn't connect to DSBMD");
}
if (i == 10)
xerr(NULL, EXIT_FAILURE, "Couldn't connect to DSBMD");
/* Get the drive list from dsbmd. */
for (ndrives = 0, p = readln(true); p[0] != '='; p = readln(true)) {
if (parse_dsbmdevent(p) == -1)
continue;
if (dsbmdevent.type == EVENT_ADD_DEVICE) {
add_drive(&dsbmdevent.drvinfo);
} else if (dsbmdevent.type == EVENT_ERROR_MSG) {
if (dsbmdevent.code != ERR_PERMISSION_DENIED)
continue;
xerrx(NULL, EXIT_FAILURE,
_("You are not allowed to connect to DSBMD"));
} else if (dsbmdevent.type == EVENT_SHUTDOWN) {
xerrx(NULL, EXIT_FAILURE, _("DSBMD just shut down."));
}
}
ioc = g_io_channel_unix_new(fileno(sock));
iotag = g_io_add_watch(ioc, G_IO_IN, readevent, NULL);
(void)signal(SIGCHLD, catch_child);
(void)signal(SIGTERM, cleanup);
(void)signal(SIGINT, cleanup);
(void)signal(SIGHUP, cleanup);
(void)signal(SIGQUIT, cleanup);
/* Init proc table */
for (i = 0; i < NPROCS; i++)
proctbl[i].pid = -1;
create_mainwin();
for (;;) {
gtk_main();
/* Block SIGCHLD */
sigemptyset(&sigmask); sigaddset(&sigmask, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigmask, NULL);
for (i = 0; i < NPROCS; i++) {
if (proctbl[i].pid == -1)
continue;
if (proctbl[i].error == EXIT_ENOENT) {
/* We couldn't execute the program. */
errno = ENOENT;
xwarn(mainwin.win,
_("Couldn't execute command \"%s\""),
proctbl[i].cmdstr);
free(proctbl[i].cmdstr);
proctbl[i].pid = -1;
} else if (proctbl[i].error == EXIT_EXEC_ERR) {
errno = proctbl[i].saved_errno;
xwarn(mainwin.win,
_("Failed to execute shell \"%s\""),
_PATH_BSHELL);
free(proctbl[i].cmdstr);
proctbl[i].pid = -1;
}
}
/* Unblock SIGCHLD. */
sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
}
}
static void
usage()
{
(void)printf("Usage: %s [-ih] [<disk image> ...]\n" \
" -i: Start %s as tray icon\n", PROGRAM, PROGRAM);
exit(EXIT_FAILURE);
}
static void
create_mainwin()
{
GdkPixbuf *icon;
GtkWidget *menu, *root_menu, *menu_bar, *item, *sw, *image, *vbox;
if ((icon = load_icon(32, "drive-harddisk-usb",
"drive-removable-media", "drive-harddisk", NULL)) == NULL) {
icon = load_icon(32, "image-missing", NULL);
}
mainwin.win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
gtk_window_set_default_size(mainwin.win, *mainwin.width,
*mainwin.height);
gtk_window_set_title(mainwin.win, TITLE);
gtk_window_set_resizable(mainwin.win, TRUE);
gtk_window_set_icon(mainwin.win, icon);
load_pixbufs();
create_icon_list();
/* Create the menu for the menu bar and the tray icon. */
menu = gtk_menu_new();
image = gtk_image_new_from_icon_name("preferences-system", GTK_ICON_SIZE_MENU);
item = gtk_image_menu_item_new_with_mnemonic(_("_Preferences"));
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect(G_OBJECT(item), "activate",
G_CALLBACK(settings_menu), NULL);
image = gtk_image_new_from_icon_name("application-exit", GTK_ICON_SIZE_MENU);
item = gtk_image_menu_item_new_with_mnemonic(_("_Quit"));
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
g_signal_connect(G_OBJECT(item), "activate",
G_CALLBACK(cleanup), NULL);
root_menu = gtk_menu_item_new_with_mnemonic(_("_File"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(root_menu), menu);
menu_bar = gtk_menu_bar_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), root_menu);
gtk_widget_show(menu_bar);
mainwin.store = gtk_list_store_new(NUM_COLS, G_TYPE_STRING,
GDK_TYPE_PIXBUF, G_TYPE_POINTER, G_TYPE_STRING);
mainwin.icon_view =
gtk_icon_view_new_with_model(GTK_TREE_MODEL(mainwin.store));
gtk_icon_view_set_text_column(GTK_ICON_VIEW(mainwin.icon_view),
COL_NAME);
gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(mainwin.icon_view),
COL_PIXBUF);
mainwin.store = create_icontbl(mainwin.store);
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(sw), mainwin.icon_view);
mainwin.statusbar = gtk_statusbar_new();
#if GTK_MAJOR_VERSION < 3
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(mainwin.statusbar),
FALSE);
#endif
#if GTK_MAJOR_VERSION < 3
vbox = gtk_vbox_new(FALSE, 0);
#else
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
#endif
gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), mainwin.statusbar, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(mainwin.win), vbox);
mainwin.tray_icon = gtk_status_icon_new_from_pixbuf(icon);
g_signal_connect(G_OBJECT(mainwin.icon_view),
"button-press-event", G_CALLBACK(icon_clicked), NULL);
g_signal_connect(G_OBJECT(mainwin.tray_icon), "activate",
G_CALLBACK(tray_click), mainwin.win);
g_signal_connect(G_OBJECT(mainwin.tray_icon), "popup-menu",
G_CALLBACK(popup_tray_ctxmenu), G_OBJECT(menu));
gtk_status_icon_set_tooltip_text(mainwin.tray_icon, "DSBMC");
gtk_status_icon_set_visible(mainwin.tray_icon, TRUE);
g_signal_connect(mainwin.win, "delete-event",
G_CALLBACK(hide_win), NULL);
g_signal_connect(G_OBJECT(mainwin.win), "window-state-event",
G_CALLBACK(window_state_event), mainwin.tray_icon);
g_signal_connect(G_OBJECT(mainwin.win), "configure-event",
G_CALLBACK(window_state_event), mainwin.win);
if (*mainwin.posx >= 0 && *mainwin.posy >= 0)
gtk_window_move(GTK_WINDOW(mainwin.win),
*mainwin.posx, *mainwin.posy);
if (mainwin.win_state != GDK_WINDOW_STATE_WITHDRAWN)
gtk_widget_show_all(GTK_WIDGET(mainwin.win));
}
static void
hide_win(GtkWidget *win)
{
gtk_window_get_position(GTK_WINDOW(win), mainwin.posx, mainwin.posy);
if (*mainwin.posx < 0 || *mainwin.posy < 0 ||
gdk_screen_width() - *mainwin.posx < 0 ||
gdk_screen_height() - *mainwin.posy < 0)
*mainwin.posx = *mainwin.posy = 0;
gtk_window_get_size(GTK_WINDOW(win), mainwin.width, mainwin.height);
gtk_widget_hide(win);
}
static gboolean
window_state_event(GtkWidget *wdg, GdkEvent *event, gpointer unused)
{
switch ((int)event->type) {
case GDK_CONFIGURE:
*mainwin.posx = ((GdkEventConfigure *)event)->x;
*mainwin.posy = ((GdkEventConfigure *)event)->y;
*mainwin.width = ((GdkEventConfigure *)event)->width;
*mainwin.height = ((GdkEventConfigure *)event)->height;
dsbcfg_write(PROGRAM, PATH_CONFIG, cfg);
break;
case GDK_WINDOW_STATE:
mainwin.win_state =
((GdkEventWindowState *)event)->new_window_state;
dsbcfg_write(PROGRAM, PATH_CONFIG, cfg);
break;
}
return (FALSE);
}
static void
tray_click(GtkStatusIcon *status_icon, gpointer win)
{
if ((mainwin.win_state & GDK_WINDOW_STATE_ICONIFIED) ||
(mainwin.win_state & GDK_WINDOW_STATE_WITHDRAWN) ||
(mainwin.win_state & GDK_WINDOW_STATE_BELOW)) {
if ((mainwin.win_state & GDK_WINDOW_STATE_ICONIFIED))
gtk_window_deiconify(win);
if (*mainwin.posx >= 0 && *mainwin.posy >= 0) {
gtk_window_move(GTK_WINDOW(win),
*mainwin.posx, *mainwin.posy);
}
gtk_widget_show_all(GTK_WIDGET(win));
} else {
gtk_window_get_position(GTK_WINDOW(win),
mainwin.posx, mainwin.posy);
if (*mainwin.posx < 0 || *mainwin.posy < 0 ||
gdk_screen_width() - *mainwin.posx < 0 ||
gdk_screen_height() - *mainwin.posy < 0)
*mainwin.posx = *mainwin.posy = 0;
gtk_widget_hide(GTK_WIDGET(win));
}
}
static void
popup_tray_ctxmenu(GtkStatusIcon *icon, guint bt, guint tm, gpointer menu)
{
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bt, tm);
}
static void
settings_menu()
{
int i, j;
char *s, *q, *qs, **v;
bool error;
size_t len;
drive_t *dp;
const char *p;
GtkWidget *win, *abt, *cbt, *cb, *label, *table, *image;
GtkWidget *entry[SETTINGS_NCMDS + 1];
win = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(win), _("Preferences"));
gtk_window_set_icon_name(GTK_WINDOW(win), "preferences-system");
gtk_container_set_border_width(GTK_CONTAINER(win), 10);
table = gtk_table_new(SETTINGS_NCMDS + 1, 5, FALSE);
gtk_table_set_col_spacing(GTK_TABLE(table), 2, 10);
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 10);
for (i = 0; i < SETTINGS_NCMDS; i++) {
for (j = 0; j < PIXBUFTBLSZ; j++) {
if (strcmp(settingsmenu.cmds[i].iconid,
pixbuftbl[j].id) == 0) {
image = gtk_image_new_from_pixbuf(
pixbuftbl[j].icon);
break;
}
}
label = new_label(ALIGN_LEFT, ALIGN_CENTER,
_(settingsmenu.cmds[i].action));
entry[i] = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(entry[i]),
*settingsmenu.cmds[i].cmdstr);
gtk_entry_set_width_chars(GTK_ENTRY(entry[i]), 35);
if (settingsmenu.cmds[i].autoplay != NULL) {
cb = gtk_check_button_new_with_label("Autoplay");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb),
*settingsmenu.cmds[i].autoplay);
gtk_table_attach(GTK_TABLE(table), cb, 3, 4, i, i + 1,
GTK_EXPAND |GTK_FILL, 0, 0, 0);
g_signal_connect(cb, "toggled", G_CALLBACK(cb_cb),
settingsmenu.cmds[i].autoplay);
}
gtk_table_attach(GTK_TABLE(table), image, 0, 1, i, i + 1,
GTK_FILL, 0, 0, 0);
gtk_table_attach(GTK_TABLE(table), label, 1, 2, i, i + 1,
GTK_FILL, 0, 0, 0);
gtk_table_attach(GTK_TABLE(table), entry[i], 2, 3, i, i + 1,
GTK_EXPAND |GTK_FILL, 0, 0, 0);
label = new_pango_label(ALIGN_LEFT, ALIGN_CENTER,
_(SETTINGS_MENU_INFO_MSG));
gtk_widget_set_tooltip_text(GTK_WIDGET(entry[i]),
gtk_label_get_text(GTK_LABEL(label)));
}
for (j = 0; j < PIXBUFTBLSZ; j++) {
if (strcmp("hide", pixbuftbl[j].id) == 0) {
image = gtk_image_new_from_pixbuf(pixbuftbl[j].icon);
break;
}
}
label = new_label(ALIGN_LEFT, ALIGN_CENTER,
_("Ignore mount points/devices:"));
entry[i] = gtk_entry_new();
for (len = 0, v = *settingsmenu.ignore_list;
v != NULL && *v != NULL; v++)
len += strlen(*v) + 4;
if (len > 0) {
if ((s = malloc(len * 2)) == NULL)
xerr(mainwin.win, EXIT_FAILURE, "malloc()");
(void)memset(s, 0, len);
for (v = *settingsmenu.ignore_list;
v != NULL && *v != NULL; v++) {
qs = g_strdup_printf("%s\"%s\"",
v != *settingsmenu.ignore_list ? ", " : "", *v);
if (qs == NULL) {
xerr(mainwin.win, EXIT_FAILURE,
"g_strdup_printf()");
}
(void)strncat(s, qs, len);
len -= strlen(qs);
free(qs);
}
gtk_entry_set_text(GTK_ENTRY(entry[i]), s);
free(s);
}
gtk_widget_set_tooltip_text(GTK_WIDGET(entry[i]),
_("Comma separated list of mount points/devices to ignore\n" \
"E.g.: /var/run/user/1001/gvfs, /dev/ada0p2, ..."));
gtk_entry_set_width_chars(GTK_ENTRY(entry[i]), 35);
gtk_table_attach(GTK_TABLE(table), image, 0, 1, i, i + 1,
GTK_FILL, 0, 0, 0);
gtk_table_attach(GTK_TABLE(table), label, 1, 2, i, i + 1,
GTK_FILL, 0, 0, 0);
gtk_table_attach(GTK_TABLE(table), entry[i], 2, 3, i, i + 1,
GTK_EXPAND | GTK_FILL, 0, 0, 0);
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(win))), table,
TRUE, TRUE, 0);
abt = gtk_button_new_with_mnemonic(_("_Ok"));
cbt = gtk_button_new_with_mnemonic(_("_Cancel"));
gtk_dialog_add_action_widget(GTK_DIALOG(win), abt,
GTK_RESPONSE_ACCEPT);
gtk_dialog_add_action_widget(GTK_DIALOG(win), cbt,
GTK_RESPONSE_REJECT);
gtk_widget_show_all(win);
/* Unselect all entries. */
for (i = 0; i < SETTINGS_NCMDS + 1; i++)
gtk_editable_select_region(GTK_EDITABLE(entry[i]), 0, 0);
for (;;) {
if (gtk_dialog_run(GTK_DIALOG(win)) != GTK_RESPONSE_ACCEPT)
break;
for (i = 0; i < SETTINGS_NCMDS; i++) {
p = gtk_entry_get_text(GTK_ENTRY(entry[i]));
q = *settingsmenu.cmds[i].cmdstr;
if (strcmp(p, q) == 0)
continue;
free(q);
q = *settingsmenu.cmds[i].cmdstr = g_strdup(p);
if (q == NULL) {