summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2009-08-08 21:25:28 +0200
committerGravatar waker <wakeroid@gmail.com>2009-08-08 21:25:28 +0200
commit84527d3b733052108f0e6c49eae091d0b98712cf (patch)
treef2c0571039f77e6087d80e5f5099e5dbc5236a3e
parent0b9915275456dfee33bbce8eb31b2a0b80fb4e53 (diff)
started refactoring of gtkplaylist to share code between playlist and search windows
-rw-r--r--callbacks.c73
-rw-r--r--callbacks.h4
-rw-r--r--deadbeef.glade1
-rw-r--r--gtkplaylist.c49
-rw-r--r--gtkplaylist.h28
-rw-r--r--interface.c3
-rw-r--r--playlist.h1
-rw-r--r--search.c1
-rw-r--r--search.h2
9 files changed, 117 insertions, 45 deletions
diff --git a/callbacks.c b/callbacks.c
index caed0116..54db38b3 100644
--- a/callbacks.c
+++ b/callbacks.c
@@ -36,6 +36,7 @@
#include "messages.h"
#include "codec.h"
#include "playback.h"
+#include "search.h"
#include "cwav.h"
#include "cvorbis.h"
@@ -46,6 +47,8 @@
#include "csid.h"
extern GtkWidget *mainwin;
+static gtkplaylist_t main_playlist;
+static gtkplaylist_t search_playlist;
void
on_volume_value_changed (GtkRange *range,
@@ -89,23 +92,6 @@ on_playlist_expose_event (GtkWidget *widget,
return FALSE;
}
-void
-on_playlist_realize (GtkWidget *widget,
- gpointer user_data)
-{
- GtkTargetEntry entry = {
- .target = "STRING",
- .flags = GTK_TARGET_SAME_WIDGET/* | GTK_TARGET_OTHER_APP*/,
- TARGET_SAMEWIDGET
- };
- // setup drag-drop source
-// gtk_drag_source_set (widget, GDK_BUTTON1_MASK, &entry, 1, GDK_ACTION_MOVE);
- // setup drag-drop target
- gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, &entry, 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
- gtk_drag_dest_add_uri_targets (widget);
-// gtk_drag_dest_set_track_motion (widget, TRUE);
-}
-
gboolean
on_playlist_button_press_event (GtkWidget *widget,
@@ -608,5 +594,58 @@ on_loop_disable_activate (GtkMenuItem *menuitem,
ps_set_loop_mode (1);
}
+void
+on_playlist_realize (GtkWidget *widget,
+ gpointer user_data)
+{
+ // init playlist control structure, and put it into widget user-data
+ memset (&main_playlist, 0, sizeof (main_playlist));
+ main_playlist.playlist = widget;
+ main_playlist.header = lookup_widget (mainwin, "header");
+ main_playlist.scrollbar = lookup_widget (mainwin, "playscroll");
+ main_playlist.phead = &playlist_head;
+ main_playlist.update_statusbar = 1;
+ main_playlist.has_dragndrop = 1;
+ main_playlist.scrollpos = 0;
+ main_playlist.row = -1;
+ main_playlist.clicktime = -1;
+ main_playlist.nvisiblerows = 0;
+ main_playlist.fmtcache = NULL;
+ int colwidths[ps_ncolumns] = { 50, 200, 50, 200, 50 };
+ memcpy (main_playlist.colwidths, colwidths, sizeof (colwidths));
+ GtkTargetEntry entry = {
+ .target = "STRING",
+ .flags = GTK_TARGET_SAME_WIDGET/* | GTK_TARGET_OTHER_APP*/,
+ TARGET_SAMEWIDGET
+ };
+ // setup drag-drop source
+// gtk_drag_source_set (widget, GDK_BUTTON1_MASK, &entry, 1, GDK_ACTION_MOVE);
+ // setup drag-drop target
+ gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, &entry, 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+ gtk_drag_dest_add_uri_targets (widget);
+// gtk_drag_dest_set_track_motion (widget, TRUE);
+}
+
+void
+on_searchlist_realize (GtkWidget *widget,
+ gpointer user_data)
+{
+ // init playlist control structure, and put it into widget user-data
+ memset (&search_playlist, 0, sizeof (search_playlist));
+ search_playlist.playlist = widget;
+ search_playlist.header = lookup_widget (mainwin, "header");
+ search_playlist.scrollbar = lookup_widget (mainwin, "playscroll");
+ search_playlist.phead = &search_head;
+ search_playlist.update_statusbar = 0;
+ search_playlist.has_dragndrop = 0;
+ search_playlist.scrollpos = 0;
+ search_playlist.row = -1;
+ search_playlist.clicktime = -1;
+ search_playlist.nvisiblerows = 0;
+ search_playlist.fmtcache = NULL;
+ int colwidths[ps_ncolumns] = { 50, 200, 50, 200, 50 };
+ memcpy (search_playlist.colwidths, colwidths, sizeof (colwidths));
+
+}
diff --git a/callbacks.h b/callbacks.h
index 7bb50d1d..8c35c1ab 100644
--- a/callbacks.h
+++ b/callbacks.h
@@ -332,3 +332,7 @@ on_searchlist_scroll_event (GtkWidget *widget,
void
on_searchscroll_value_changed (GtkRange *range,
gpointer user_data);
+
+void
+on_searchlist_realize (GtkWidget *widget,
+ gpointer user_data);
diff --git a/deadbeef.glade b/deadbeef.glade
index 6db33145..11fd3453 100644
--- a/deadbeef.glade
+++ b/deadbeef.glade
@@ -1585,6 +1585,7 @@ Public License instead of this License. But first, please read
<signal name="configure_event" handler="on_searchlist_configure_event" last_modification_time="Sat, 08 Aug 2009 18:51:52 GMT"/>
<signal name="expose_event" handler="on_searchlist_expose_event" last_modification_time="Sat, 08 Aug 2009 18:52:01 GMT"/>
<signal name="scroll_event" handler="on_searchlist_scroll_event" last_modification_time="Sat, 08 Aug 2009 18:52:13 GMT"/>
+ <signal name="realize" handler="on_searchlist_realize" last_modification_time="Sat, 08 Aug 2009 19:12:45 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
diff --git a/gtkplaylist.c b/gtkplaylist.c
index 2742c222..8dc070c2 100644
--- a/gtkplaylist.c
+++ b/gtkplaylist.c
@@ -58,21 +58,18 @@ static int nvisiblerows = 0;
// cache[(ROW*ncolumns+COLUMN)*3+2] --- 0 if needs recalc
static int16_t *drawps_cache = NULL;
-#define ncolumns 5
-#define colname_max 100
-
-int refit_header[ncolumns] = {
+int refit_header[ps_ncolumns] = {
1, 1, 1, 1, 1
};
-const char *colnames[ncolumns] = {
+const char *colnames[ps_ncolumns] = {
"Playing Status",
"Artist / Album",
"Track №",
"Title / Track Artist",
"Duration"
};
-char colnames_fitted[ncolumns][colname_max];
+char colnames_fitted[ps_ncolumns][ps_colname_max];
int colwidths[] = {
50, 200, 50, 200, 50
@@ -246,7 +243,7 @@ draw_ps_row (GdkDrawable *drawable, cairo_t *cr, int row, playItem_t *it) {
int min = (int)it->duration/60;
int sec = (int)(it->duration-min*60);
snprintf (dur, 10, "%d:%02d", min, sec);
- const char *columns[ncolumns] = {
+ const char *columns[ps_ncolumns] = {
"",
ps_find_meta (it, "artist"),
ps_find_meta (it, "track"),
@@ -255,12 +252,12 @@ draw_ps_row (GdkDrawable *drawable, cairo_t *cr, int row, playItem_t *it) {
};
int x = 0;
#if 1
- for (int i = 0; i < ncolumns; i++) {
+ for (int i = 0; i < ps_ncolumns; i++) {
char str[512];
if (i > 0) {
int dotpos;
- int cidx = ((row-scrollpos) * ncolumns + i) * 3;
+ int cidx = ((row-scrollpos) * ps_ncolumns + i) * 3;
if (!drawps_cache[cidx + 2]) {
drawps_cache[cidx + 1] = fit_text (cr, str, &dotpos, 512, columns[i], colwidths[i]-10);
drawps_cache[cidx + 0] = dotpos;
@@ -300,9 +297,9 @@ draw_ps_row (GdkDrawable *drawable, cairo_t *cr, int row, playItem_t *it) {
void
draw_playlist (GtkWidget *widget, int x, int y, int w, int h) {
- if (!drawps_cache && nvisiblerows > 0 && ncolumns > 0) {
- drawps_cache = malloc (nvisiblerows * ncolumns * 3 * sizeof (int16_t));
- memset (drawps_cache, 0, nvisiblerows * ncolumns * 3 * sizeof (int16_t));
+ if (!drawps_cache && nvisiblerows > 0 && ps_ncolumns > 0) {
+ drawps_cache = malloc (nvisiblerows * ps_ncolumns * 3 * sizeof (int16_t));
+ memset (drawps_cache, 0, nvisiblerows * ps_ncolumns * 3 * sizeof (int16_t));
}
cairo_t *cr;
cr = gdk_cairo_create (backbuf);
@@ -627,26 +624,26 @@ gtkps_scroll (int newscroll) {
//printf ("scroll up\n");
int r;
for (r = nvisiblerows-1; r >= d; r--) {
- memcpy (&drawps_cache[r * ncolumns * 3], &drawps_cache[(r - d) * ncolumns * 3], sizeof (int16_t) * 3 * ncolumns);
+ memcpy (&drawps_cache[r * ps_ncolumns * 3], &drawps_cache[(r - d) * ps_ncolumns * 3], sizeof (int16_t) * 3 * ps_ncolumns);
}
for (r = 0; r < d; r++) {
- memset (&drawps_cache[r * ncolumns * 3], 0, sizeof (int16_t) * 3 * ncolumns);
+ memset (&drawps_cache[r * ps_ncolumns * 3], 0, sizeof (int16_t) * 3 * ps_ncolumns);
}
}
else {
//printf ("scroll down\n");
int r;
for (r = 0; r < nvisiblerows-d; r++) {
- memcpy (&drawps_cache[r * ncolumns * 3], &drawps_cache[(r + d) * ncolumns * 3], sizeof (int16_t) * 3 * ncolumns);
+ memcpy (&drawps_cache[r * ps_ncolumns * 3], &drawps_cache[(r + d) * ps_ncolumns * 3], sizeof (int16_t) * 3 * ps_ncolumns);
}
for (r = nvisiblerows-d; r < nvisiblerows; r++) {
- memset (&drawps_cache[r * ncolumns * 3], 0, sizeof (int16_t) * 3 * ncolumns);
+ memset (&drawps_cache[r * ps_ncolumns * 3], 0, sizeof (int16_t) * 3 * ps_ncolumns);
}
}
}
else {
// invalidate entire cache
- memset (drawps_cache, 0, sizeof (int16_t) * 3 * ncolumns * nvisiblerows);
+ memset (drawps_cache, 0, sizeof (int16_t) * 3 * ps_ncolumns * nvisiblerows);
}
scrollpos = newscroll;
GtkWidget *widget = lookup_widget (mainwin, "playlist");
@@ -1101,7 +1098,7 @@ on_playlist_drag_end (GtkWidget *widget,
gpointer user_data)
{
// invalidate entire cache - slow, but rare
- memset (drawps_cache, 0, sizeof (int16_t) * 3 * ncolumns * nvisiblerows);
+ memset (drawps_cache, 0, sizeof (int16_t) * 3 * ps_ncolumns * nvisiblerows);
draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
gtkps_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height);
}
@@ -1180,7 +1177,7 @@ gtkps_add_fm_dropped_files (char *ptr, int length, int drop_y) {
free (ptr);
ps_shuffle ();
// invalidate entire cache - slow, but rare
- memset (drawps_cache, 0, sizeof (int16_t) * 3 * ncolumns * nvisiblerows);
+ memset (drawps_cache, 0, sizeof (int16_t) * 3 * ps_ncolumns * nvisiblerows);
GDK_THREADS_ENTER();
gtk_widget_destroy (d);
gtk_widget_set_sensitive (mainwin, TRUE);
@@ -1207,7 +1204,7 @@ header_draw (GtkWidget *widget) {
int h = widget->allocation.height;
const char *detail = "toolbar";
- for (int i = 0; i < ncolumns; i++) {
+ for (int i = 0; i < ps_ncolumns; i++) {
if (x >= widget->allocation.width) {
break;
}
@@ -1225,14 +1222,14 @@ header_draw (GtkWidget *widget) {
return;
}
x = 0;
- for (int i = 0; i < ncolumns; i++) {
+ for (int i = 0; i < ps_ncolumns; i++) {
if (x >= widget->allocation.width) {
break;
}
w = colwidths[i];
cairo_move_to (cr, x + 5, 15);
if (refit_header[i]) {
- fit_text (cr, colnames_fitted[i], NULL, colname_max, colnames[i], colwidths[i]-10);
+ fit_text (cr, colnames_fitted[i], NULL, ps_colname_max, colnames[i], colwidths[i]-10);
refit_header[i] = 0;
}
cairo_show_text (cr, colnames_fitted[i]);
@@ -1306,7 +1303,7 @@ on_header_motion_notify_event (GtkWidget *widget,
//printf ("ev->x = %d, w = %d\n", (int)event->x, newx - x - 2);
refit_header[header_sizing] = 1;
for (int k = 0; k < nvisiblerows; k++) {
- int cidx = (k * ncolumns + header_sizing) * 3;
+ int cidx = (k * ps_ncolumns + header_sizing) * 3;
drawps_cache[cidx+2] = 0;
}
header_draw (widget);
@@ -1316,7 +1313,7 @@ on_header_motion_notify_event (GtkWidget *widget,
}
else {
int x = 0;
- for (int i = 0; i < ncolumns; i++) {
+ for (int i = 0; i < ps_ncolumns; i++) {
int w = colwidths[i];
if (event->x >= x + w - 2 && event->x <= x + w) {
gdk_window_set_cursor (widget->window, cursor_sz);
@@ -1343,7 +1340,7 @@ on_header_button_press_event (GtkWidget *widget,
header_dragpt[0] = event->x;
header_dragpt[1] = event->y;
int x = 0;
- for (int i = 0; i < ncolumns; i++) {
+ for (int i = 0; i < ps_ncolumns; i++) {
int w = colwidths[i];
if (event->x >= x + w - 2 && event->x <= x + w) {
header_sizing = i;
@@ -1369,7 +1366,7 @@ on_header_button_release_event (GtkWidget *widget,
header_dragging = -1;
header_sizing = -1;
int x = 0;
- for (int i = 0; i < ncolumns; i++) {
+ for (int i = 0; i < ps_ncolumns; i++) {
int w = colwidths[i];
if (event->x >= x + w - 2 && event->x <= x + w) {
gdk_window_set_cursor (widget->window, cursor_sz);
diff --git a/gtkplaylist.h b/gtkplaylist.h
index fabc03b7..feab283f 100644
--- a/gtkplaylist.h
+++ b/gtkplaylist.h
@@ -27,8 +27,32 @@ enum {
TARGET_SAMEWIDGET,
};
-void
-gtkps_nextsong (void);
+#define ps_ncolumns 5
+#define ps_colname_max 100
+
+// structure of this kind must be set as user data for playlist, header and scrollbar widgets
+// pointer to this structure must be passed too all functions that
+// implement playlist functionality (like this pointer)
+typedef struct {
+ // cached gtk/gdk object pointers
+ GtkWidget *playlist;
+ GtkWidget *header;
+ GtkWidget *scrollbar;
+ GdkPixmap *backbuf;
+ // parameters
+ playItem_t **phead; // pointer to head of list to display
+ int update_statusbar; // whether it needs to update status bar in certain cases
+ int has_dragndrop; // whether it has drag and drop capability
+ // current state
+ int scrollpos;
+ int row;
+ double clicktime; // for doubleclick detection
+ int nvisiblerows;
+ int16_t *fmtcache; // cached text formatting
+ int header_fitted[ps_ncolumns];
+ char colnames_fitted[ps_ncolumns][ps_colname_max]; // cached formatted names of columns
+ int colwidths[ps_ncolumns]; // current column widths
+} gtkplaylist_t;
void
redraw_ps_row (GtkWidget *widget, int row);
diff --git a/interface.c b/interface.c
index fed79079..0f638d55 100644
--- a/interface.c
+++ b/interface.c
@@ -764,6 +764,9 @@ create_searchwin (void)
g_signal_connect ((gpointer) searchlist, "scroll_event",
G_CALLBACK (on_searchlist_scroll_event),
NULL);
+ g_signal_connect ((gpointer) searchlist, "realize",
+ G_CALLBACK (on_searchlist_realize),
+ NULL);
g_signal_connect ((gpointer) searchscroll, "value_changed",
G_CALLBACK (on_searchscroll_value_changed),
NULL);
diff --git a/playlist.h b/playlist.h
index 2a1501ae..8e33c53e 100644
--- a/playlist.h
+++ b/playlist.h
@@ -35,6 +35,7 @@ typedef struct playItem_s {
struct playItem_s *next; // next item in linked list
struct playItem_s *prev; // prev item in linked list
struct playItem_s *shufflenext; // next item in shuffle list
+ struct playItem_s *searchnext; // next in search results list
struct metaInfo_s *meta; // linked list storing metainfo
unsigned selected : 1;
} playItem_t;
diff --git a/search.c b/search.c
index ce09fba5..abc90b83 100644
--- a/search.c
+++ b/search.c
@@ -31,6 +31,7 @@
#include "search.h"
static GtkWidget *searchwin = NULL;
+struct playItem_s *search_head = NULL;
void
search_start (void) {
diff --git a/search.h b/search.h
index b90e1903..93f31505 100644
--- a/search.h
+++ b/search.h
@@ -18,6 +18,8 @@
#ifndef __SEARCH_H
#define __SEARCH_H
+extern struct playItem_s *search_head;
+
void
search_start (void);