minimal mingw32 compilation fixes
[melted_gui] / src / main.c
1 /*
2 * main.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
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.
14 *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <gtk/gtk.h>
25 #include <unistd.h>
26 #include <string.h>
27
28 #ifdef ENABLE_NLS
29 #include <libintl.h>
30 #endif
31
32 #include <stdio.h>
33 #include "ui.h"
34 #include "omnplay.h"
35 #include "support.h"
36
37 #ifdef _WIN32
38 #include <ctype.h>
39 #include <windows.h>
40
41 char *strcasestr(char *haystack, char *needle)
42 {
43 char *p, *startn = 0, *np = 0;
44
45 for (p = haystack; *p; p++) {
46 if (np) {
47 if (toupper(*p) == toupper(*np)) {
48 if (!*++np)
49 return startn;
50 } else
51 np = 0;
52 } else if (toupper(*p) == toupper(*needle)) {
53 np = needle + 1;
54 startn = p;
55 }
56 }
57
58 return 0;
59 };
60 #endif /* _WIN32 */
61
62 int main(int argc, char **argv)
63 {
64 char path[ 512 ], *buf;
65 omnplay_instance_t *app = NULL;
66
67 #ifdef ENABLE_NLS
68 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
69 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
70 textdomain (GETTEXT_PACKAGE);
71 #endif
72
73 g_thread_init(NULL);
74 gdk_threads_init();
75 gtk_set_locale();
76 gtk_init(&argc, &argv);
77
78 memset(path, 0, sizeof(path));
79 #ifdef _WIN32
80 GetModuleFileName(NULL, path, sizeof(path));
81 // g_warning("GetModuleFileName [%s]\n", path);
82 if((buf = strstr(path, "\\bin\\omnplay.exe")))
83 {
84 buf[0] = 0;
85 strcat(path, "\\share\\omnplay\\pixmaps");
86 }
87 #else
88 // Linux hack to determine path of the executable
89 readlink( "/proc/self/exe", path, sizeof(path));
90 g_warning ("path=(%s)\n", path);
91 if((buf = strstr(path, "/bin/omnplay")))
92 {
93 buf[0] = 0;
94 strcat(path, "/share/omnplay/pixmaps");
95 }
96 else if((buf = strstr(path, "/src/omnplay")))
97 {
98 buf[0] = 0;
99 strcat( path, "/pixmaps" );
100 }
101 else
102 snprintf(path, sizeof(path), "%s/%s/pixmaps", PACKAGE_DATA_DIR, PACKAGE);
103 #endif /* _WIN32 */
104
105 add_pixmap_directory( path );
106 g_warning ("add_pixmap_directory(%s)\n", path);
107
108 app = omnplay_create(argc, argv);
109
110 if(app->window)
111 {
112 gtk_widget_show (app->window);
113 gdk_threads_enter();
114 omnplay_init(app);
115 gtk_main ();
116 gdk_threads_leave();
117 };
118
119 omnplay_destroy(app);
120
121 return 0;
122 }
123