prepare for library rebuild
authorMaksym Veremeyenko <verem@m1stereo.tv>
Wed, 27 Jun 2012 15:40:45 +0000 (18:40 +0300)
committerMaksym Veremeyenko <verem@m1stereo.tv>
Wed, 27 Jun 2012 15:40:45 +0000 (18:40 +0300)
src/Makefile.am
src/instance.c
src/instance.h
src/library.c
src/library.h [new file with mode: 0644]
src/ui.c

index 16224b8..bb6a338 100644 (file)
@@ -23,10 +23,9 @@ melted_gui_SOURCES = \
        ui_buttons.c ui_buttons.h \
        player.c player.h \
        playlist.c playlist.h \
+       library.c library.h \
        opts.c opts.h
 # \
-#      playlist.c \
-#      library.c \
 #      whois.c \
 #      omnplay.cpp omnplay.h
 
index 757d8a6..1ae08c3 100644 (file)
 #include "opts.h"
 #include "timecode.h"
 #include "player.h"
+#include "library.h"
+
+gboolean instance_button_click(instance_t* app, control_buttons_t button)
+{
+#if 0
+    switch(button)
+    {
+        case BUTTON_PLAYLIST_ITEM_ADD:
+            omnplay_playlist_item_add(app, 0);
+            break;
+        case BUTTON_PLAYLIST_ITEM_DEL:
+            omnplay_playlist_item_del(app);
+            break;
+        case BUTTON_PLAYLIST_ITEM_EDIT:
+            omnplay_playlist_item_edit(app);
+            break;
+        case BUTTON_PLAYLIST_LOAD:
+            omnplay_playlist_load(app);
+            break;
+        case BUTTON_PLAYLIST_SAVE:
+            omnplay_playlist_save(app);
+            break;
+        case BUTTON_PLAYLIST_BLOCK_SINGLE:
+        case BUTTON_PLAYLIST_BLOCK_LOOP:
+            omnplay_playlist_block(app, button);
+            break;
+        case BUTTON_PLAYLIST_ITEM_UP:
+            omnplay_playlist_item_swap(app, -1);
+            break;
+        case BUTTON_PLAYLIST_ITEM_DOWN:
+            omnplay_playlist_item_swap(app, +1);
+            break;
+        case BUTTON_PLAYER_CUE:
+        case BUTTON_PLAYER_PLAY:
+        case BUTTON_PLAYER_PAUSE:
+        case BUTTON_PLAYER_STOP:
+            omnplay_ctl(app, button);
+            break;
+        case BUTTON_LIBRARY_ADD:
+            omnplay_library_add(app, 0);
+            break;
+        case BUTTON_LIBRARY_REFRESH:
+            omnplay_library_refresh(app);
+            break;
+        case BUTTON_LIBRARY_FIND:
+            omnplay_library_search(app, 0);
+            break;
+        case BUTTON_LIBRARY_FIND_NEXT:
+            omnplay_library_search(app, 1);
+            break;
+        case BUTTON_PLAYLIST_RELINK:
+            omnplay_playlist_relink(app);
+            break;
+    };
+#endif
+    return TRUE;
+};
+
+static gboolean on_button_click(GtkWidget *button, gpointer user_data)
+{
+    int i;
+    instance_t* app = (instance_t*)user_data;
+
+    for(i = 1; i < BUTTON_LAST; i++)
+        if(app->buttons[i] == button)
+            return instance_button_click(app, (control_buttons_t)i);
+
+    return FALSE;
+};
 
 static gboolean on_main_window_delete_event( GtkWidget *widget, GdkEvent *event, gpointer user_data )
 {
@@ -120,16 +189,13 @@ void instance_init(instance_t* app)
     for(i = 0; i < app->players.count; i++)
         player_run(app, i);
 
-#if 0
-
     /* attach buttons click */
     for(i = 1; i < BUTTON_LAST; i++)
         gtk_signal_connect(GTK_OBJECT(app->buttons[i]), "clicked",
             GTK_SIGNAL_FUNC( on_button_click), app );
 
     /* load library */
-    omnplay_library_load(app);
-#endif
+    library_init(app);
 
 #if 0
     /* setup drag n drop source/target */
@@ -160,6 +226,8 @@ void instance_release(instance_t* app)
 
     app->f_exit = 1;
 
+    library_release(app);
+
     /* stop unit monitoring threads */
     for(i = 0; i < app->players.count; i++)
         player_stop(app, i);
index 8c6d1fb..99b3de6 100644 (file)
@@ -132,7 +132,7 @@ typedef struct instance_desc
 {
     GtkWidget *window;
     GtkWidget *playlist_grid;
-    GtkWidget *library_grid;
+    GtkWidget *library_tree;
     GtkWidget *buttons[BUTTON_LAST + 1];
     GtkWidget *status_label;
     struct
@@ -155,6 +155,7 @@ typedef struct instance_desc
     } playlist;
     struct
     {
+        void* handle[2];
         playlist_item_t item[MAX_LIBRARY_ITEMS];
         int count;
         char filename[PATH_MAX];
index 62bed43..0ca9e38 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * playlist.c -- GTK+ 2 omnplay
- * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
+ * library.c -- GTK+ 2 melted gui
+ * Copyright (C) 2012 Maksym Veremeyenko <verem@m1stereo.tv>
  *
  * 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
 #include <pthread.h>
 #include <string.h>
 
-#include "omnplay.h"
+#include <mvcp/mvcp.h>
+#include <mvcp/mvcp_remote.h>
+
+#include "instance.h"
 #include "ui.h"
 #include "timecode.h"
 
+void library_release(instance_t* app)
+{
+    mvcp_close(app->library.handle[0]);
+    mvcp_parser_close(app->library.handle[1]);
+};
+
+void library_init(instance_t* app)
+{
+    /* connect to library */
+    app->library.handle[1] = mvcp_parser_init_remote(app->players.host, 5250);
+    app->library.handle[0] = mvcp_init(app->library.handle[1]);
+    if(mvcp_connect(app->library.handle[0]) != mvcp_ok)
+    {
+        g_warning("library_init: failed to connect to server %s", app->players.host);
+        return;
+    };
+#if 0
+    pthread_mutex_lock(&app->library.lock);
+
+    if(app->library.filename[0])
+    {
+        app->library.count = MAX_LIBRARY_ITEMS;
+        omnplay_library_load_file(app->library.item, &app->library.count, app->library.filename);
+    };
+
+    omnplay_library_sort(app);
+
+    pthread_mutex_unlock(&app->library.lock);
+
+    omnplay_library_draw(app);
+#endif
+};
+
+#if 0
 playlist_item_t* omnplay_library_find(omnplay_instance_t* app, char* id)
 {
     int i;
@@ -218,22 +255,6 @@ int omnplay_library_load_file(playlist_item_t* items, int *pcount, char* filenam
     return r;
 };
 
-void omnplay_library_load(omnplay_instance_t* app)
-{
-    pthread_mutex_lock(&app->library.lock);
-
-    if(app->library.filename[0])
-    {
-        app->library.count = MAX_LIBRARY_ITEMS;
-        omnplay_library_load_file(app->library.item, &app->library.count, app->library.filename);
-    };
-
-    omnplay_library_sort(app);
-
-    pthread_mutex_unlock(&app->library.lock);
-
-    omnplay_library_draw(app);
-};
 
 static void omnplay_library_save_file(playlist_item_t* item, int count, char* filename)
 {
@@ -483,3 +504,5 @@ void omnplay_library_search(omnplay_instance_t* app, int next)
 
     pthread_mutex_unlock(&app->library.lock);
 };
+
+#endif
diff --git a/src/library.h b/src/library.h
new file mode 100644 (file)
index 0000000..d7e72db
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * library.h -- GTK+ 2 melted gui
+ * Copyright (C) 2012 Maksym Veremeyenko <verem@m1stereo.tv>
+ *
+ * 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 LIBRARY_H
+#define LIBRARY_H
+
+#include "instance.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+void library_init(instance_t* app);
+void library_release(instance_t* app);
+
+#ifdef __cplusplus
+};
+#endif /* __cplusplus */
+
+#endif /* LIBRARY_H */
index 824272b..9ceebfe 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -192,7 +192,7 @@ static GtkWidget* create_treeview(GtkWidget* top, char* name, const column_desc_
     return treeview;
 };
 
-static GtkWidget* pane_library_grid(GtkWidget* top, instance_t* app)
+static GtkWidget* pane_library_tree(GtkWidget* top, instance_t* app)
 {
     GtkWidget *scrolledwindow;
 
@@ -202,7 +202,7 @@ static GtkWidget* pane_library_grid(GtkWidget* top, instance_t* app)
         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
     gtk_container_add (GTK_CONTAINER (scrolledwindow),
-        app->library_grid = create_treeview(top, "treeview_library", library_columns));
+        app->library_tree = create_treeview(top, "treeview_library", library_columns));
 
     return scrolledwindow;
 }
@@ -269,7 +269,7 @@ static GtkWidget* pane_library(GtkWidget* top, instance_t* app)
 
     /* add grid */
     gtk_box_pack_start (GTK_BOX (vbox),
-        pane_library_grid(top, app),
+        pane_library_tree(top, app),
         TRUE, TRUE, 0);
 
     /* add search buttons */