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 "irreco_webdb_dlg.h"
25 #include <gdk-pixbuf/gdk-pixbuf.h>
27 #include <irreco_webdb.h>
28 #include <irreco_retry_loop.h>
34 * Irreco is a remote control application for Nokia Internet Tablets. With
35 * Irreco and the help of external IR transceiver you can control IR compatible
36 * devices like televisions, DVD players and AV Receivers. Irreco also has a
37 * remote editor which you can use to place buttons to the screen and build the
38 * kind of remote you want to use.
40 * @par Irreco elsewhere
41 * @li Homepage: http://irreco.garage.maemo.org/
42 * @li Garage project: https://garage.maemo.org/projects/irreco/
43 * @li Mailing list: https://garage.maemo.org/mailman/listinfo/irreco-everything
44 * @li Internet Tablet Talk Thread:
45 * http://www.internettablettalk.com/forums/showthread.php?t=15919
46 * @li Maemo Downloads page: http://maemo.org/downloads/product/OS2008/irreco/
49 * @li Irreco Class documentation can be found in
50 * @htmlonly<a class="el" href="modules.html">Modules</a>@endhtmlonly page.
52 * @par How to implement irreco backend
53 * @li First take a look at @ref IrrecoBackendApi.
54 * @li Then make a copy of @ref PageIrrecoBackendTemplate.
55 * @li And write some code :)
59 * @addtogroup Irreco Internal Irreco Classes
64 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
66 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
67 void irreco_parse_args(int * argc
, char **argv
[]);
68 void irreco_process_args(IrrecoData
*irreco_data
);
69 void irreco_link_bg_image_dir();
73 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
75 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
78 * Popup help message if user doesnt have any remotes.
80 gboolean
irreco_startup_help_check(IrrecoData
*irreco_data
)
83 if (irreco_string_table_is_empty(irreco_data
->irreco_layout_array
)) {
85 if (irreco_window_user_create_new_remote(irreco_data
,
86 irreco_window_manager_get_gtk_window(
87 irreco_data
->window_manager
))) {
89 irreco_show_webdb_dlg(irreco_data
,
90 irreco_window_manager_get_gtk_window(
91 irreco_data
->window_manager
));
93 irreco_window_manager_show(irreco_data
->window_manager
,
96 irreco_info_dlg(irreco_window_manager_get_gtk_window(
97 irreco_data
->window_manager
),
98 _(IRRECO_NO_REMOTE_HELP
));
101 IRRECO_RETURN_BOOL(FALSE
);
104 int main(int argc
, char *argv
[])
106 IrrecoData
*irreco_data
;
107 osso_context_t
* osso_context
= NULL
;
111 setlocale(LC_ALL
, "");
112 IRRECO_DEBUG("bindtextdomain: \"%s\"\n",
113 bindtextdomain(GETTEXT_PACKAGE
, LOCALEDIR
));
114 IRRECO_DEBUG("bind_textdomain_codeset: \"%s\"\n",
115 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8"));
116 IRRECO_DEBUG("textdomain: \"%s\"\n", textdomain(GETTEXT_PACKAGE
));
118 /* Create program main data structure & parse arguments. */
119 irreco_data
= irreco_data_new();
120 irreco_parse_args(&argc
, &argv
);
121 IRRECO_DEBUG("LOCALEDIR: %s\n", LOCALEDIR
);
122 IRRECO_DEBUG("GETTEXT_PACKAGE: %s\n", GETTEXT_PACKAGE
);
124 irreco_process_args(irreco_data
);
126 /* Init Web Database*/
129 /* Initialize the GTK. */
131 /*gdk_threads_init();*/
132 gtk_init(&argc
, &argv
);
134 /* Initialize libosso and maemo dbus thingy. */
135 osso_context
= osso_initialize(PACKAGE_DBUS_NAME
, PACKAGE_VERSION
,
137 if (osso_context
== NULL
) {
138 IRRECO_PRINTF("Failed to init LibOSSO\n");
143 g_set_application_name(IRRECO_APP_NAME_SHORT
);
144 irreco_window_manager_show(irreco_data
->window_manager
,
149 IrrecoBackendManager
* manager
= irreco_data
->irreco_backend_manager
;
150 irreco_backend_manager_load_lib_dir(manager
, IRRECO_BACKEND_DIR
);
151 irreco_config_read_backends(manager
);
152 irreco_backend_manager_print(manager
);
153 irreco_backend_manager_read_from_confs(manager
);
154 irreco_backend_manager_get_devcmd_lists(manager
);
158 irreco_data
->theme_manager
= irreco_theme_manager_new(irreco_data
);
159 irreco_config_read_layouts(irreco_data
);
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 irreco_data_free(irreco_data
);
179 osso_deinitialize(osso_context
);
180 irreco_webdb_finalize();
181 IRRECO_RETURN_INT(0);
186 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
187 /* Command line argument parsing. */
188 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
190 static gchar
** style_dir_array
= NULL
;
191 static gchar
** style_file_array
= NULL
;
192 static GOptionEntry irreco_option_entries
[] = {
193 { "button-style-dir", 'B', 0, G_OPTION_ARG_FILENAME_ARRAY
,
194 &style_dir_array
, "Read button styles files from directory", "DIR" },
195 /*{ "button-style-file", 'b', 0, G_OPTION_ARG_FILENAME_ARRAY,
196 &style_file_array, "Read button style from file.", "FILE" },*/
197 { "debug", 'd', 0, G_OPTION_ARG_INT
, &IRRECO_DEBUG_LEVEL_VAR
,
198 "Debugging ouput level", "N" },
202 void irreco_parse_args(int * argc
, char **argv
[])
205 GError
*error
= NULL
;
206 GOptionContext
*context
;
209 /* Format help title. */
210 help_title
= g_strjoin("", "- ", IRRECO_APP_NAME_LONG
,
211 " v", VERSION
, NULL
);
212 context
= g_option_context_new(help_title
);
215 /* Parse arguments. */
216 g_option_context_add_main_entries(context
, irreco_option_entries
,
218 g_option_context_add_group(context
, gtk_get_option_group(TRUE
));
219 g_option_context_parse(context
, argc
, argv
, &error
);
220 if (irreco_gerror_check_print(&error
)) {
223 g_option_context_free(context
);
227 void irreco_process_args(IrrecoData
*irreco_data
)
230 gboolean file_error
= FALSE
;
233 /* Check file filetypes. */
234 if (style_dir_array
!= NULL
) {
235 for (array_pos
= g_strv_length(style_dir_array
); array_pos
--;) {
236 if (!irreco_is_dir(style_dir_array
[array_pos
])) {
237 IRRECO_ERROR("\"%s\" is not a directory.\n",
238 style_dir_array
[array_pos
]);
243 if (style_file_array
!= NULL
) {
244 for (array_pos
= g_strv_length(style_file_array
); array_pos
--;) {
245 if (!irreco_is_file(style_file_array
[array_pos
])) {
246 IRRECO_ERROR("\"%s\" is not a file.\n",
247 style_file_array
[array_pos
]);
256 /* Read button configurations. */
257 if (style_dir_array
!= NULL
) {
258 for (array_pos
= g_strv_length(style_dir_array
); array_pos
--;) {
259 IRRECO_PRINTF("Reading button styles from \"%s\".\n",
260 style_dir_array
[array_pos
]);
261 /*irreco_config_read_themes_from_dir(
262 irreco_data, style_dir_array[array_pos]);*/
263 irreco_theme_manager_read_themes_from_dir(
264 irreco_data
->theme_manager
,
265 style_dir_array
[array_pos
]);
267 g_strfreev(style_dir_array
);
268 style_dir_array
= NULL
;
275 * Default Irreco background images are installed to somewhere under /usr/lib.
276 * That location is not normally accessible with the Maemo file selection
277 * dialog. So in order to work around that, we create a symlink into
278 * $HOME/MyDocs/.images/ which points to that directory.
280 void irreco_link_bg_image_dir()
283 const gchar link_name
[] = "Irreco default backgrounds";
286 oldpwd
= getenv("PWD");
287 if (chdir(getenv("HOME")) != 0 || chdir("MyDocs/.images/") != 0) {
288 IRRECO_ERROR("Could not chdir into "
289 "\"$HOME/MyDocs/.images/\".\n");
293 if (irreco_file_exists(link_name
)) {
294 IRRECO_PRINTF("File \"%s\" already exists.\n", link_name
);
295 } else if(symlink(IRRECO_BG_IMAGE_DIR
, link_name
) == 0) {
296 IRRECO_PRINTF("Created link from \"%s\" as \"%s\".\n",
297 link_name
, IRRECO_BG_IMAGE_DIR
);
299 IRRECO_ERROR("Could not make a link from \"%s\" to \"%s\".\n",
300 link_name
, IRRECO_BG_IMAGE_DIR
);