2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "irreco_data.h"
22 #include "irreco_config.h"
23 #include "irreco_window_user.h"
24 #include <gdk-pixbuf/gdk-pixbuf.h>
26 #include <irreco_webdb.h>
27 #include <irreco_retry_loop.h>
33 * Irreco is a remote control application for Nokia Internet Tablets. With
34 * Irreco and the help of external IR transceiver you can control IR compatible
35 * devices like televisions, DVD players and AV Receivers. Irreco also has a
36 * remote editor which you can use to place buttons to the screen and build the
37 * kind of remote you want to use.
39 * @par Irreco elsewhere
40 * @li Homepage: http://irreco.garage.maemo.org/
41 * @li Garage project: https://garage.maemo.org/projects/irreco/
42 * @li Mailing list: https://garage.maemo.org/mailman/listinfo/irreco-everything
43 * @li Internet Tablet Talk Thread:
44 * http://www.internettablettalk.com/forums/showthread.php?t=15919
45 * @li Maemo Downloads page: http://maemo.org/downloads/product/OS2008/irreco/
48 * @li Irreco Class documentation can be found in
49 * @htmlonly<a class="el" href="modules.html">Modules</a>@endhtmlonly page.
51 * @par How to implement irreco backend
52 * @li First take a look at @ref IrrecoBackendApi.
53 * @li Then make a copy of @ref PageIrrecoBackendTemplate.
54 * @li And write some code :)
58 * @addtogroup Irreco Internal Irreco Classes
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
65 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
66 void irreco_parse_args(int * argc
, char **argv
[]);
67 void irreco_process_args(IrrecoData
*irreco_data
);
68 void irreco_link_bg_image_dir();
72 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
77 * Popup help message if user doesnt have any remotes.
79 gboolean
irreco_startup_help_check(IrrecoData
*irreco_data
)
83 if (irreco_string_table_is_empty(irreco_data
->irreco_layout_array
)) {
85 irreco_info_dlg(irreco_window_manager_get_gtk_window(
86 irreco_data
->window_manager
),
87 _(IRRECO_STARTUP_NO_REMOTE
));
89 if (!irreco_show_remote_download_dlg(irreco_data
,
90 irreco_window_manager_get_gtk_window(
91 irreco_data
->window_manager
))) {
92 irreco_info_dlg(irreco_window_manager_get_gtk_window(
93 irreco_data
->window_manager
),
94 _(IRRECO_NO_REMOTE_HELP
));
97 IRRECO_RETURN_BOOL(FALSE
);
100 int main(int argc
, char *argv
[])
102 IrrecoData
*irreco_data
;
103 osso_context_t
* osso_context
= NULL
;
107 setlocale(LC_ALL
, "");
108 IRRECO_DEBUG("bindtextdomain: \"%s\"\n",
109 bindtextdomain(GETTEXT_PACKAGE
, LOCALEDIR
));
110 IRRECO_DEBUG("bind_textdomain_codeset: \"%s\"\n",
111 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8"));
112 IRRECO_DEBUG("textdomain: \"%s\"\n", textdomain(GETTEXT_PACKAGE
));
114 /* Create program main data structure & parse arguments. */
115 irreco_data
= irreco_data_new();
116 irreco_parse_args(&argc
, &argv
);
117 IRRECO_DEBUG("LOCALEDIR: %s\n", LOCALEDIR
);
118 IRRECO_DEBUG("GETTEXT_PACKAGE: %s\n", GETTEXT_PACKAGE
);
120 irreco_process_args(irreco_data
);
122 /* Init Web Database*/
125 /* Initialize the GTK. */
127 /*gdk_threads_init();*/
128 gtk_init(&argc
, &argv
);
130 /* Initialize libosso and maemo dbus thingy. */
131 osso_context
= osso_initialize(PACKAGE_DBUS_NAME
, PACKAGE_VERSION
,
133 if (osso_context
== NULL
) {
134 IRRECO_PRINTF("Failed to init LibOSSO\n");
139 g_set_application_name(IRRECO_APP_NAME_SHORT
);
140 irreco_window_manager_show(irreco_data
->window_manager
,
145 IrrecoBackendManager
* manager
= irreco_data
->irreco_backend_manager
;
146 irreco_backend_manager_load_lib_dir(manager
, IRRECO_BACKEND_DIR
);
147 irreco_config_read_backends(manager
);
148 irreco_backend_manager_print(manager
);
149 irreco_backend_manager_read_from_confs(manager
);
150 irreco_backend_manager_get_devcmd_lists(manager
);
154 irreco_data
->theme_manager
= irreco_theme_manager_new(irreco_data
);
155 irreco_config_read_layouts_from_files(irreco_data
);
157 /* Start Lirc daemon */
158 system("sudo /etc/init.d/lirc start");
159 system("sudo /etc/init.d/lirc reload");
161 /* Create link to background image dir. */
162 irreco_link_bg_image_dir();
164 /* Begin the main application. */
165 irreco_window_manager_set_layout(irreco_data
->window_manager
,
166 irreco_config_read_active_layout(
168 g_idle_add(G_SOURCEFUNC(irreco_startup_help_check
), irreco_data
);
171 /* Save active layout. */
172 if (irreco_data
->window_manager
->current_layout
!= NULL
) {
173 irreco_config_save_active_layout(
174 irreco_data
->window_manager
->current_layout
);
178 system("sudo /etc/init.d/lirc stop");
179 irreco_data_free(irreco_data
);
180 osso_deinitialize(osso_context
);
181 irreco_webdb_finalize();
182 IRRECO_RETURN_INT(0);
187 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
188 /* Command line argument parsing. */
189 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
191 static gchar
** style_dir_array
= NULL
;
192 static gchar
** style_file_array
= NULL
;
193 static GOptionEntry irreco_option_entries
[] = {
194 { "button-style-dir", 'B', 0, G_OPTION_ARG_FILENAME_ARRAY
,
195 &style_dir_array
, "Read button styles files from directory", "DIR" },
196 /*{ "button-style-file", 'b', 0, G_OPTION_ARG_FILENAME_ARRAY,
197 &style_file_array, "Read button style from file.", "FILE" },*/
198 { "debug", 'd', 0, G_OPTION_ARG_INT
, &IRRECO_DEBUG_LEVEL_VAR
,
199 "Debugging ouput level", "N" },
203 void irreco_parse_args(int * argc
, char **argv
[])
206 GError
*error
= NULL
;
207 GOptionContext
*context
;
210 /* Format help title. */
211 help_title
= g_strjoin("", "- ", IRRECO_APP_NAME_LONG
,
212 " v", VERSION
, NULL
);
213 context
= g_option_context_new(help_title
);
216 /* Parse arguments. */
217 g_option_context_add_main_entries(context
, irreco_option_entries
,
219 g_option_context_add_group(context
, gtk_get_option_group(TRUE
));
220 g_option_context_parse(context
, argc
, argv
, &error
);
221 if (irreco_gerror_check_print(&error
)) {
224 g_option_context_free(context
);
228 void irreco_process_args(IrrecoData
*irreco_data
)
231 gboolean file_error
= FALSE
;
234 /* Check file filetypes. */
235 if (style_dir_array
!= NULL
) {
236 for (array_pos
= g_strv_length(style_dir_array
); array_pos
--;) {
237 if (!irreco_is_dir(style_dir_array
[array_pos
])) {
238 IRRECO_ERROR("\"%s\" is not a directory.\n",
239 style_dir_array
[array_pos
]);
244 if (style_file_array
!= NULL
) {
245 for (array_pos
= g_strv_length(style_file_array
); array_pos
--;) {
246 if (!irreco_is_file(style_file_array
[array_pos
])) {
247 IRRECO_ERROR("\"%s\" is not a file.\n",
248 style_file_array
[array_pos
]);
257 /* Read button configurations. */
258 if (style_dir_array
!= NULL
) {
259 for (array_pos
= g_strv_length(style_dir_array
); array_pos
--;) {
260 IRRECO_PRINTF("Reading button styles from \"%s\".\n",
261 style_dir_array
[array_pos
]);
262 /*irreco_config_read_themes_from_dir(
263 irreco_data, style_dir_array[array_pos]);*/
264 irreco_theme_manager_read_themes_from_dir(
265 irreco_data
->theme_manager
,
266 style_dir_array
[array_pos
]);
268 g_strfreev(style_dir_array
);
269 style_dir_array
= NULL
;
276 * Default Irreco background images are installed to somewhere under /usr/lib.
277 * That location is not normally accessible with the Maemo file selection
278 * dialog. So in order to work around that, we create a symlink into
279 * $HOME/MyDocs/.images/ which points to that directory.
281 void irreco_link_bg_image_dir()
284 const gchar link_name
[] = "Irreco default backgrounds";
287 oldpwd
= getenv("PWD");
288 if (chdir(getenv("HOME")) != 0 || chdir("MyDocs/.images/") != 0) {
289 IRRECO_ERROR("Could not chdir into "
290 "\"$HOME/MyDocs/.images/\".\n");
294 if (irreco_file_exists(link_name
)) {
295 IRRECO_PRINTF("File \"%s\" already exists.\n", link_name
);
296 } else if(symlink(IRRECO_BG_IMAGE_DIR
, link_name
) == 0) {
297 IRRECO_PRINTF("Created link from \"%s\" as \"%s\".\n",
298 link_name
, IRRECO_BG_IMAGE_DIR
);
300 IRRECO_ERROR("Could not make a link from \"%s\" to \"%s\".\n",
301 link_name
, IRRECO_BG_IMAGE_DIR
);