From e44b8496425b348e22165e767b3e8fa52dcad953 Mon Sep 17 00:00:00 2001 From: Maksym Veremeyenko Date: Fri, 17 Jun 2011 15:50:52 +0300 Subject: [PATCH] introduce basic player structs --- src/Makefile.am | 1 + src/main.c | 16 +++++--- src/omnplay.cpp | 18 +++++++++- src/omnplay.h | 23 ++++++++++++- src/opts.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/opts.h | 38 +++++++++++++++++++++ 6 files changed, 186 insertions(+), 9 deletions(-) create mode 100644 src/opts.c create mode 100644 src/opts.h diff --git a/src/Makefile.am b/src/Makefile.am index 014b1e5..1c83cb8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,6 +12,7 @@ omnplay_SOURCES = \ support.c support.h \ ui.c ui.h ui_utils.h \ ui_buttons.c ui_buttons.h \ + opts.c opts.h \ omnplay.cpp omnplay.h omnplay_LDADD = @GTHREAD_LIBS@ @GTK_LIBS@ @OM_LIBS@ diff --git a/src/main.c b/src/main.c index 2e9149a..94edc7a 100644 --- a/src/main.c +++ b/src/main.c @@ -75,14 +75,18 @@ int main(int argc, char **argv) #endif /* _WIN32 */ app = omnplay_create(argc, argv); - gtk_widget_show (app->window); - gdk_threads_enter(); - omnplay_init(app); - gtk_main (); - gdk_threads_leave(); + if(app->window) + { + gtk_widget_show (app->window); + gdk_threads_enter(); + omnplay_init(app); + gtk_main (); + omnplay_release(app); + gdk_threads_leave(); + }; - omnplay_close(app); + omnplay_destroy(app); return 0; } diff --git a/src/omnplay.cpp b/src/omnplay.cpp index 06c9804..cdf2c99 100644 --- a/src/omnplay.cpp +++ b/src/omnplay.cpp @@ -29,6 +29,7 @@ #include "omnplay.h" #include "ui.h" +#include "opts.h" #include "omplrclnt.h" @@ -41,20 +42,29 @@ static gboolean on_main_window_delete_event( GtkWidget *widget, GdkEvent *event, omnplay_instance_t* omnplay_create(int argc, char** argv) { + int i, c; omnplay_instance_t* app; + /* prepare application instance */ app = (omnplay_instance_t*)malloc(sizeof(omnplay_instance_t)); memset(app, 0, sizeof(omnplay_instance_t)); - app->window = ui_omnplay(app); + /* load parameters from command line */ + if(!omnplay_opt(argc, argv, app) && app->players.count) + app->window = ui_omnplay(app); + else + omnplay_usage(); return app; }; -void omnplay_close(omnplay_instance_t* app) + +void omnplay_destroy(omnplay_instance_t* app) { + free(app); }; + #if 0 static void test() { @@ -115,3 +125,7 @@ void omnplay_init(omnplay_instance_t* app) test(); #endif }; + +void omnplay_release(omnplay_instance_t* app) +{ +}; diff --git a/src/omnplay.h b/src/omnplay.h index 0d1ab64..2c3b41d 100644 --- a/src/omnplay.h +++ b/src/omnplay.h @@ -51,16 +51,37 @@ typedef enum control_buttons BUTTON_LAST } control_buttons_t; +#define MAX_PLAYERS 4 + +typedef struct omnplay_player +{ + char name[PATH_MAX]; + char host[PATH_MAX]; + void* handle; + pthread_t thread; + pthread_mutex_t lock; + GtkWidget *label_status, *label_state, *label_cur, *label_rem, *label_clip; +} +omnplay_player_t; + typedef struct omnplay_instance { GtkWidget *window; GtkWidget *buttons[BUTTON_LAST + 1]; + struct + { + omnplay_player_t item[MAX_PLAYERS]; + int count; + char path[PATH_MAX]; + } players; + int f_exit; } omnplay_instance_t; omnplay_instance_t* omnplay_create(int argc, char** argv); void omnplay_init(omnplay_instance_t* app); -void omnplay_close(omnplay_instance_t* app); +void omnplay_release(omnplay_instance_t* app); +void omnplay_destroy(omnplay_instance_t* app); #ifdef __cplusplus }; diff --git a/src/opts.c b/src/opts.c new file mode 100644 index 0000000..4c5efe0 --- /dev/null +++ b/src/opts.c @@ -0,0 +1,99 @@ +/* + * opts.c -- GTK+ 2 omnplay + * Copyright (C) 2011 Maksym Veremeyenko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include + +#include +#include + +#include "opts.h" + +static const char short_options [] = "h"; +static const struct option long_options [] = +{ + { "directory", required_argument, NULL, '0'}, + { "player", required_argument, NULL, '1'}, + { "help", no_argument, NULL, 'h'}, + { 0, 0, 0, 0} +}; + + + +int omnplay_opt(int argc, char** argv, omnplay_instance_t* app) +{ + char* p; + int c, index = 0; + + /* reset datas */ + optind = 0; opterr = 0; optopt = 0; + + /* program arguments processing */ + while(1) + { + c = getopt_long (argc, argv, short_options, long_options, &index); + + if((-1) == c) break; + + switch(c) + { + case 0: break; + + /** --direcotry */ + case '0': + strncpy(app->players.path, optarg, PATH_MAX); + break; + + /** --player */ + case '1': + p = strchr(optarg, '@'); + if(p) + { + *p = 0; + strncpy(app->players.item[app->players.count].name, optarg, PATH_MAX); + strncpy(app->players.item[app->players.count].host, p + 1, PATH_MAX); + app->players.count++; + }; + break; + + default: + fprintf(stderr, "ERROR: Incorrect argument!\n"); + return 1; + break; + }; + }; + + return 0; +}; + +void omnplay_usage(void) +{ + fprintf + ( + stderr, + "Usage:\n" + "\t--directory= Directory to override default\n" + "\t--player= Player to use in a form @\n" + ); +}; diff --git a/src/opts.h b/src/opts.h new file mode 100644 index 0000000..3fd8ffd --- /dev/null +++ b/src/opts.h @@ -0,0 +1,38 @@ +/* + * opts.h -- GTK+ 2 omnplay + * Copyright (C) 2011 Maksym Veremeyenko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef OPTS_H +#define OPTS_H + +#include "omnplay.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +int omnplay_opt(int argc, char** argv, omnplay_instance_t* app); +void omnplay_usage(); + +#ifdef __cplusplus +}; +#endif /* __cplusplus */ + + +#endif /* OPTS_H */ -- 1.7.4.4