1 /* $Id$ */
2 /* Copyright (c) 2011-2012 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Desktop Phone */
4 /* This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>. */
15 
16 
17 
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <locale.h>
22 #include <libintl.h>
23 #include <gtk/gtk.h>
24 #include <Desktop.h>
25 #include "phone.h"
26 #include "../config.h"
27 #define _(string) gettext(string)
28 
29 /* constants */
30 #ifndef PREFIX
31 # define PREFIX		"/usr/local"
32 #endif
33 #ifndef DATADIR
34 # define DATADIR	PREFIX "/share"
35 #endif
36 #ifndef LOCALEDIR
37 # define LOCALEDIR	DATADIR "/locale"
38 #endif
39 
40 
41 /* private */
42 /* functions */
43 /* usage */
_usage(void)44 static int _usage(void)
45 {
46 	fputs(_("Usage: phonectl -C\n"
47 "       phonectl -D\n"
48 "       phonectl -L\n"
49 "       phonectl -M\n"
50 "       phonectl -S\n"
51 "       phonectl -W\n"
52 "       phonectl -r\n"
53 "       phonectl -s\n"
54 "  -C	Open the contacts window\n"
55 "  -D	Show the dialer\n"
56 "  -L	Open the phone log window\n"
57 "  -M	Open the messages window\n"
58 "  -S	Display or change settings\n"
59 "  -W	Write a new message\n"
60 "  -r	Resume telephony operation\n"
61 "  -s	Suspend telephony operation\n"), stderr);
62 	return 1;
63 }
64 
65 
66 /* public */
67 /* functions */
68 /* main */
main(int argc,char * argv[])69 int main(int argc, char * argv[])
70 {
71 	int o;
72 	int type = PHONE_MESSAGE_SHOW;
73 	int action = -1;
74 
75 	setlocale(LC_ALL, "");
76 	bindtextdomain(PACKAGE, LOCALEDIR);
77 	textdomain(PACKAGE);
78 	gtk_init(&argc, &argv);
79 	while((o = getopt(argc, argv, "CDLMSWrs")) != -1)
80 		switch(o)
81 		{
82 			case 'C':
83 				if(action != -1)
84 					return _usage();
85 				action = PHONE_MESSAGE_SHOW_CONTACTS;
86 				break;
87 			case 'D':
88 				if(action != -1)
89 					return _usage();
90 				action = PHONE_MESSAGE_SHOW_DIALER;
91 				break;
92 			case 'L':
93 				if(action != -1)
94 					return _usage();
95 				action = PHONE_MESSAGE_SHOW_LOGS;
96 				break;
97 			case 'M':
98 				if(action != -1)
99 					return _usage();
100 				action = PHONE_MESSAGE_SHOW_MESSAGES;
101 				break;
102 			case 'S':
103 				if(action != -1)
104 					return _usage();
105 				action = PHONE_MESSAGE_SHOW_SETTINGS;
106 				break;
107 			case 'W':
108 				if(action != -1)
109 					return _usage();
110 				action = PHONE_MESSAGE_SHOW_WRITE;
111 				break;
112 			case 'r':
113 				if(action != -1)
114 					return _usage();
115 				type = PHONE_MESSAGE_POWER_MANAGEMENT;
116 				action = PHONE_MESSAGE_POWER_MANAGEMENT_RESUME;
117 				break;
118 			case 's':
119 				if(action != -1)
120 					return _usage();
121 				type = PHONE_MESSAGE_POWER_MANAGEMENT;
122 				action = PHONE_MESSAGE_POWER_MANAGEMENT_SUSPEND;
123 				break;
124 			default:
125 				return _usage();
126 		}
127 	if(action < 0)
128 		return _usage();
129 	desktop_message_send(PHONE_CLIENT_MESSAGE, type, action, TRUE);
130 	return 0;
131 }
132