summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorq66 <quaker66@gmail.com>2014-01-08 16:16:53 +0100
committerq66 <quaker66@gmail.com>2014-01-08 16:17:10 +0100
commit58e7897cc6df6425f771dfd894ebc24353f1d97d (patch)
treece768dc7829c017600d738fa6039905ed8f76f4a
parentdddc1d72e54f0f965eb1690f9b9e27396ecdf7e3 (diff)
handle more options stuffHEADmaster
-rw-r--r--src/Makefile.am2
-rw-r--r--src/enity.h74
-rw-r--r--src/main.c107
3 files changed, 174 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index e2b6a97..bf7e742 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,3 +11,5 @@ enity_LDFLAGS = $(LTLIBINTL)
11 11
12localedir = $(datadir)/locale 12localedir = $(datadir)/locale
13DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ 13DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
14
15EXTRA_DIST = enity.h
diff --git a/src/enity.h b/src/enity.h
new file mode 100644
index 0000000..87a58d2
--- /dev/null
+++ b/src/enity.h
@@ -0,0 +1,74 @@
1/* Enity: a drop-in Zenity replacement
2 *
3 * See COPYING for licensing.
4 *
5 * This is the mainy header.
6 */
7
8#ifndef ENITY_HDR
9#define ENITY_HDR
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18
19#include <Eina.h>
20#include <Ecore_Getopt.h>
21#include <Elementary.h>
22
23typedef struct Enity_General_Opts {
24 char *title;
25 char *window_icon;
26 int width;
27 int height;
28 double timeout;
29 char *ok_label;
30 char *cancel_label;
31 Eina_Bool modal;
32} Enity_General_Opts;
33
34enum {
35 ENITY_APP_CALENDAR = 0,
36 ENITY_APP_ENTRY,
37 ENITY_APP_ERROR,
38 ENITY_APP_INFO,
39 ENITY_APP_FILE_SELECTION,
40 ENITY_APP_LIST,
41 ENITY_APP_NOTIFICATION,
42 ENITY_APP_PROGRESS,
43 ENITY_APP_QUESTION,
44 ENITY_APP_WARNING,
45 ENITY_APP_SCALE,
46 ENITY_APP_TEXT_INFO,
47 ENITY_APP_COLOR_SELECTION,
48 ENITY_APP_PASSWORD,
49 ENITY_APP_FORMS,
50 ENITY_NUMAPPS
51};
52
53typedef struct Enity_App_Opts {
54 Eina_Bool calendar;
55 Eina_Bool entry;
56 Eina_Bool error;
57 Eina_Bool info;
58 Eina_Bool file_selection;
59 Eina_Bool list;
60 Eina_Bool notification;
61 Eina_Bool progress;
62 Eina_Bool question;
63 Eina_Bool warning;
64 Eina_Bool scale;
65 Eina_Bool text_info;
66 Eina_Bool color_selection;
67 Eina_Bool password;
68 Eina_Bool forms;
69} Enity_App_Opts;
70
71extern Enity_General_Opts opts_general;
72extern Enity_App_Opts opts_app;
73
74#endif \ No newline at end of file
diff --git a/src/main.c b/src/main.c
index 7136809..93dc2c3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,33 +5,110 @@
5 * This is the main entry. 5 * This is the main entry.
6 */ 6 */
7 7
8#include <Ecore_Getopt.h> 8#include "enity.h"
9#include <Elementary.h>
10 9
11#include "config.h" 10Enity_General_Opts opts_general;
11Enity_App_Opts opts_app;
12
13#define DIALOGOPT(name, optname) ECORE_GETOPT_STORE_TRUE(0, optname, \
14 "Application: display " name " dialog.")
12 15
13static const Ecore_Getopt opt = { 16static const Ecore_Getopt opt = {
14 "enity", "%prog [arguments]", PACKAGE_VERSION, 17 "enity", NULL, PACKAGE_VERSION,
15 "See COPYING for copyright information.", 18 "See COPYING for copyright information.",
16 "See COPYING for licensing information.", 19 "See COPYING for licensing information.",
17 "A drop-in EFL based zenity replacement.", 0, { 20 "A drop-in EFL based zenity replacement.", 0, {
18 /* add more options */ 21 /* general program options */
19 ECORE_GETOPT_LICENSE('l', "license"), 22 ECORE_GETOPT_LICENSE('l', "license"),
20 ECORE_GETOPT_COPYRIGHT('c', "copyright"), 23 ECORE_GETOPT_COPYRIGHT('c', "copyright"),
21 ECORE_GETOPT_VERSION('v', "version"), 24 ECORE_GETOPT_VERSION('v', "version"),
22 ECORE_GETOPT_HELP('h', "help"), 25 ECORE_GETOPT_HELP('h', "help"),
26 ECORE_GETOPT_STORE_TRUE(0, "about", "About enity."),
27
28 /* general enity options */
29 ECORE_GETOPT_STORE_STR(0, "title", "General: set the dialog title."),
30 ECORE_GETOPT_STORE_STR(0, "window-icon", "General: set the window "
31 "icon."),
32 ECORE_GETOPT_STORE_INT(0, "width", "General: set the width."),
33 ECORE_GETOPT_STORE_INT(0, "height", "General: set the height."),
34 ECORE_GETOPT_STORE_DOUBLE(0, "timeout", "General: set dialog timeout "
35 "in seconds."),
36 ECORE_GETOPT_STORE_STR(0, "ok-label", "General: sets the label of "
37 "the OK button."),
38 ECORE_GETOPT_STORE_STR(0, "cancel-label", "General: sets the label of "
39 "the Cancel button."),
40 ECORE_GETOPT_STORE_TRUE(0, "modal", "General: set the modal hint."),
41
42 /* enity type options */
43 DIALOGOPT("calendar", "calendar"),
44 DIALOGOPT("entry", "entry"),
45 DIALOGOPT("error", "error"),
46 DIALOGOPT("info", "info"),
47 DIALOGOPT("file selection", "file-selection"),
48 DIALOGOPT("list", "list"),
49 ECORE_GETOPT_STORE_TRUE(0, "notification", "Application: display "
50 "notification."),
51 DIALOGOPT("progress indication", "progress"),
52 DIALOGOPT("question", "question"),
53 DIALOGOPT("warning", "warning"),
54 DIALOGOPT("scale", "scale"),
55 DIALOGOPT("text information", "text-info"),
56 DIALOGOPT("color selection", "color-selection"),
57 DIALOGOPT("password", "password"),
58 DIALOGOPT("forms", "forms"),
59 ECORE_GETOPT_STORE_INT(0, "display", "Application: X display to use."),
60
61 /* TODO: options for program class/program name etc. as in zenity */
62
23 ECORE_GETOPT_SENTINEL 63 ECORE_GETOPT_SENTINEL
24 } 64 }
25}; 65};
26 66
67static void enity_shutdown(Eina_Bool fatal) {
68 elm_shutdown();
69 exit(fatal);
70}
71
27EAPI_MAIN int elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) { 72EAPI_MAIN int elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) {
28 Eina_Bool quit = EINA_FALSE; 73 Eina_Bool quit = EINA_FALSE, about = EINA_FALSE;
74
75 memset(&opts_general, 0, sizeof(Enity_General_Opts));
76 memset(&opts_app, 0, sizeof(Enity_App_Opts));
77
29 Ecore_Getopt_Value vals[] = { 78 Ecore_Getopt_Value vals[] = {
30 ECORE_GETOPT_VALUE_BOOL(quit), /* license */ 79 ECORE_GETOPT_VALUE_BOOL(quit), /* license */
31 ECORE_GETOPT_VALUE_BOOL(quit), /* copyright */ 80 ECORE_GETOPT_VALUE_BOOL(quit), /* copyright */
32 ECORE_GETOPT_VALUE_BOOL(quit), /* version */ 81 ECORE_GETOPT_VALUE_BOOL(quit), /* version */
33 ECORE_GETOPT_VALUE_BOOL(quit), /* help */ 82 ECORE_GETOPT_VALUE_BOOL(quit), /* help */
34 ECORE_GETOPT_VALUE_NONE 83
84 ECORE_GETOPT_VALUE_BOOL(about),
85
86 ECORE_GETOPT_VALUE_STR(opts_general.title),
87 ECORE_GETOPT_VALUE_STR(opts_general.window_icon),
88 ECORE_GETOPT_VALUE_INT(opts_general.width),
89 ECORE_GETOPT_VALUE_INT(opts_general.height),
90 ECORE_GETOPT_VALUE_DOUBLE(opts_general.timeout),
91 ECORE_GETOPT_VALUE_STR(opts_general.ok_label),
92 ECORE_GETOPT_VALUE_STR(opts_general.cancel_label),
93 ECORE_GETOPT_VALUE_BOOL(opts_general.modal),
94
95 ECORE_GETOPT_VALUE_BOOL(opts_app.calendar),
96 ECORE_GETOPT_VALUE_BOOL(opts_app.entry),
97 ECORE_GETOPT_VALUE_BOOL(opts_app.error),
98 ECORE_GETOPT_VALUE_BOOL(opts_app.info),
99 ECORE_GETOPT_VALUE_BOOL(opts_app.file_selection),
100 ECORE_GETOPT_VALUE_BOOL(opts_app.list),
101 ECORE_GETOPT_VALUE_BOOL(opts_app.notification),
102 ECORE_GETOPT_VALUE_BOOL(opts_app.progress),
103 ECORE_GETOPT_VALUE_BOOL(opts_app.question),
104 ECORE_GETOPT_VALUE_BOOL(opts_app.warning),
105 ECORE_GETOPT_VALUE_BOOL(opts_app.scale),
106 ECORE_GETOPT_VALUE_BOOL(opts_app.text_info),
107 ECORE_GETOPT_VALUE_BOOL(opts_app.color_selection),
108 ECORE_GETOPT_VALUE_BOOL(opts_app.password),
109 ECORE_GETOPT_VALUE_BOOL(opts_app.forms),
110
111 ECORE_GETOPT_VALUE_NONE /* terminate */
35 }; 112 };
36 113
37#if ENABLE_NLS 114#if ENABLE_NLS
@@ -43,13 +120,25 @@ EAPI_MAIN int elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) {
43 120
44 ecore_getopt_parse(&opt, vals, argc, argv); 121 ecore_getopt_parse(&opt, vals, argc, argv);
45 122
46 if (quit) goto quit; 123 /* check for multiple app options */
124 Eina_Bool *apps = (Eina_Bool*)&opts_app;
125 int num = 0, i;
126 for (i = 0; i < ENITY_NUMAPPS; ++i) {
127 if (apps[i]) {
128 if (!num) ++num;
129 else {
130 fprintf(stderr, "Two or more dialog options specified.\n");
131 enity_shutdown(EINA_TRUE);
132 }
133 }
134 }
135
136 if (quit) enity_shutdown(EINA_FALSE);
47 137
48 /* init stuff here */ 138 /* init stuff here */
49 139
50 elm_run(); 140 elm_run();
51 141
52quit:
53 elm_shutdown(); 142 elm_shutdown();
54 return 0; 143 return 0;
55} 144}