quick-lounge-applet r267 - in trunk: . src
- From: paobac svn gnome org
- To: svn-commits-list gnome org
- Subject: quick-lounge-applet r267 - in trunk: . src
- Date: Wed, 11 Feb 2009 17:37:53 +0000 (UTC)
Author: paobac
Date: Wed Feb 11 17:37:53 2009
New Revision: 267
URL: http://svn.gnome.org/viewvc/quick-lounge-applet?rev=267&view=rev
Log:
2009-02-11 Paolo Bacchilega <paobac svn gnome org>
* src/quick-lounge.c:
* src/quick-button.c:
* src/quick-box.h:
* src/quick-box.c:
New feature: Allow to add url launchers by dropping a file between
launchers. On the other hand if the file is dropped on a launcher
than the file will be opened with that launcher.
Modified:
trunk/ChangeLog
trunk/src/quick-box.c
trunk/src/quick-box.h
trunk/src/quick-button.c
trunk/src/quick-lounge.c
Modified: trunk/src/quick-box.c
==============================================================================
--- trunk/src/quick-box.c (original)
+++ trunk/src/quick-box.c Wed Feb 11 17:37:53 2009
@@ -67,6 +67,7 @@
int drag_pos_begin;
int drag_pos;
+ QuickDropPos drop_position;
GtkWidget *popup_menu;
PopulateMenuFunc populate_menu_func;
@@ -821,13 +822,19 @@
children = gtk_container_get_children (GTK_CONTAINER (quick_box));
i = 0;
- for (scan = children; scan && (i <= pos); scan = scan->next) {
+ for (scan = children; scan; scan = scan->next) {
GtkWidget *child_widget = scan->data;
- cx = child_widget->allocation.x;
- cy = child_widget->allocation.y;
- cwidth = child_widget->allocation.width;
- cheight = child_widget->allocation.height;
+ if (! QUICK_IS_BUTTON (child_widget))
+ continue;
+
+ if (i == pos) {
+ cx = child_widget->allocation.x;
+ cy = child_widget->allocation.y;
+ cwidth = child_widget->allocation.width;
+ cheight = child_widget->allocation.height;
+ break;
+ }
i++;
}
@@ -847,7 +854,7 @@
QuickBox *quick_box = QUICK_BOX (widget);
int drag_pos;
int drag_pos_begin;
-
+
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
drag_pos = quick_box->priv->drag_pos;
@@ -855,32 +862,68 @@
if ((drag_pos != -1) && (drag_pos != drag_pos_begin)) {
GdkRectangle r;
-
+
+#if 0
+ switch (quick_box->priv->drop_position) {
+ case QUICK_DROP_POSITION_INTO_OR_BEFORE:
+ g_print ("DropPosition: (%d) Into-Or-Before\n", drag_pos);
+ break;
+ case QUICK_DROP_POSITION_INTO_OR_AFTER:
+ g_print ("DropPosition: (%d) Into-Or-After\n", drag_pos);
+ break;
+ case QUICK_DROP_POSITION_BEFORE:
+ g_print ("DropPosition: (%d) Before\n", drag_pos);
+ break;
+ case QUICK_DROP_POSITION_AFTER:
+ g_print ("DropPosition: (%d) After\n", drag_pos);
+ break;
+ }
+#endif
+
get_drag_destination_rect (quick_box,
quick_box->priv->drag_pos,
&r);
- gdk_draw_line (widget->window,
- widget->style->black_gc,
- r.x,
- r.y + r.height - 1,
- r.x + r.width - 1,
- r.y + r.height - 1);
-
- if ((drag_pos_begin != -1) && (drag_pos < drag_pos_begin))
- gdk_draw_line (widget->window,
- widget->style->black_gc,
- r.x,
- r.y,
- r.x,
- r.y + r.height - 1);
- else
- gdk_draw_line (widget->window,
- widget->style->black_gc,
- r.x + r.width - 1,
- r.y,
- r.x + r.width - 1,
- r.y + r.height - 1);
+ if (quick_box->priv->drop_position == QUICK_DROP_POSITION_BEFORE) {
+ switch (get_gtk_orientation (quick_box)) {
+ case GTK_ORIENTATION_HORIZONTAL:
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ r.x,
+ r.y,
+ r.x,
+ r.y + r.height - 1);
+ break;
+ case GTK_ORIENTATION_VERTICAL:
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ r.x,
+ r.y,
+ r.x + r.width - 1,
+ r.y);
+ break;
+ }
+ }
+ else if (quick_box->priv->drop_position == QUICK_DROP_POSITION_AFTER) {
+ switch (get_gtk_orientation (quick_box)) {
+ case GTK_ORIENTATION_HORIZONTAL:
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ r.x + r.width - 1,
+ r.y,
+ r.x + r.width - 1,
+ r.y + r.height - 1);
+ break;
+ case GTK_ORIENTATION_VERTICAL:
+ gdk_draw_line (widget->window,
+ widget->style->black_gc,
+ r.x,
+ r.y + r.height - 1,
+ r.x + r.width - 1,
+ r.y + r.height - 1);
+ break;
+ }
+ }
}
if (GTK_WIDGET_HAS_FOCUS (widget)
@@ -1445,21 +1488,118 @@
}
+static QuickDropPos
+get_drop_position_for_rect (QuickBox *quick_box,
+ GdkRectangle *rect,
+ int x,
+ int y)
+{
+ gboolean before;
+ gboolean inside;
+ float dx;
+ float dy;
+ float border_x;
+ float border_y;
+
+ dx = x - rect->x;
+ dy = y - rect->y;
+ border_x = ((float) rect->width) / 4.0;
+ border_y = ((float) rect->height) / 4.0;
+
+ switch (get_gtk_orientation (quick_box)) {
+ case GTK_ORIENTATION_HORIZONTAL:
+ before = dx < (((float) rect->width) / 2.0);
+ inside = (dx > border_x) && (dx < rect->width - border_x);
+ break;
+ case GTK_ORIENTATION_VERTICAL:
+ before = dy < (((float) rect->height) / 2.0);
+ inside = (dy > border_y) && (dy < rect->height - border_y);
+ break;
+ }
+
+ if (before) {
+ if (inside)
+ return QUICK_DROP_POSITION_INTO_OR_BEFORE;
+ else
+ return QUICK_DROP_POSITION_BEFORE;
+ }
+ else {
+ if (inside)
+ return QUICK_DROP_POSITION_INTO_OR_AFTER;
+ else
+ return QUICK_DROP_POSITION_AFTER;
+ }
+
+ return QUICK_DROP_POSITION_BEFORE;
+}
+
+
+int
+quick_box_get_drop_position (QuickBox *quick_box,
+ int x,
+ int y,
+ QuickDropPos *drop_position)
+{
+ GtkBox *box = GTK_BOX (quick_box);
+ GList *children, *scan;
+ int pos;
+
+ children = gtk_container_get_children (GTK_CONTAINER (quick_box));
+ if (children == NULL) {
+ if (drop_position != NULL)
+ *drop_position = QUICK_DROP_POSITION_BEFORE;
+ return -1;
+ }
+
+ pos = 0;
+ for (scan = children; scan; scan = scan->next) {
+ GtkWidget *child_widget = scan->data;
+ GdkRectangle rect = child_widget->allocation;
+
+ if (! QUICK_IS_BUTTON (child_widget))
+ continue;
+
+ rect.x -= box->spacing;
+ rect.y -= box->spacing;
+ rect.width += box->spacing * 2;
+ rect.height += box->spacing * 2;
+
+ if ((x >= rect.x) && (x <= rect.x + rect.width)
+ && (y >= rect.y) && (y <= rect.y + rect.height))
+ {
+ if (drop_position != NULL)
+ *drop_position = get_drop_position_for_rect (quick_box, &rect, x, y);
+ g_list_free (children);
+ return pos;
+ }
+
+ pos++;
+ }
+ g_list_free (children);
+
+ if (drop_position != NULL)
+ *drop_position = QUICK_DROP_POSITION_AFTER;
+
+ return pos - 1;
+}
+
+
static void
-draw_drag_destination (QuickBox *quick_box,
- int pos)
+draw_drag_destination (QuickBox *quick_box,
+ int pos,
+ QuickDropPos drop_pos)
{
GtkWidget *widget = GTK_WIDGET (quick_box);
GdkRectangle r;
- if (pos == quick_box->priv->drag_pos)
+ if ((pos == quick_box->priv->drag_pos) && (drop_pos == quick_box->priv->drop_position))
return;
- if (quick_box->priv->drag_pos != -1) {
+ if (pos != quick_box->priv->drag_pos) {
+ quick_button_set_dnd_highlight (QUICK_BUTTON (quick_box_get_child_at_pos (quick_box, quick_box->priv->drag_pos)), FALSE);
get_drag_destination_rect (quick_box,
quick_box->priv->drag_pos,
&r);
-
gtk_widget_queue_draw_area (widget,
r.x,
r.y,
@@ -1467,8 +1607,18 @@
r.height);
}
- get_drag_destination_rect (quick_box, pos, &r);
quick_box->priv->drag_pos = pos;
+ quick_box->priv->drop_position = drop_pos;
+
+ if ((quick_box->priv->drop_position == QUICK_DROP_POSITION_INTO_OR_BEFORE)
+ || (quick_box->priv->drop_position == QUICK_DROP_POSITION_INTO_OR_AFTER))
+ {
+ quick_button_set_dnd_highlight (QUICK_BUTTON (quick_box_get_child_at_pos (quick_box, quick_box->priv->drag_pos)), TRUE);
+ }
+ else
+ quick_button_set_dnd_highlight (QUICK_BUTTON (quick_box_get_child_at_pos (quick_box, quick_box->priv->drag_pos)), FALSE);
+
+ get_drag_destination_rect (quick_box, pos, &r);
gtk_widget_queue_draw_area (widget,
r.x,
r.y,
@@ -1484,13 +1634,14 @@
gint y,
guint time)
{
- QuickBox *quick_box = QUICK_BOX (widget);
- int pos;
-
- pos = quick_box_get_pointer_position (quick_box, x, y);
+ QuickBox *quick_box = QUICK_BOX (widget);
+ int pos;
+ QuickDropPos drop_pos;
+
+ pos = quick_box_get_drop_position (quick_box, x, y, &drop_pos);
if ((pos == -1) && (_gtk_container_get_n_children (GTK_CONTAINER (widget)) == 0))
pos = 0;
- draw_drag_destination (quick_box, pos);
+ draw_drag_destination (quick_box, pos, drop_pos);
return TRUE;
}
@@ -1509,6 +1660,7 @@
quick_box->priv->drag_pos_begin = -1;
+ quick_button_set_dnd_highlight (QUICK_BUTTON (quick_box_get_child_at_pos (quick_box, quick_box->priv->drag_pos)), FALSE);
get_drag_destination_rect (quick_box, quick_box->priv->drag_pos, &r);
quick_box->priv->drag_pos = -1;
gtk_widget_queue_draw_area (widget,
@@ -1523,7 +1675,7 @@
button_drag_started_cb (GtkWidget *button,
QuickBox *quick_box)
{
- quick_box->priv->drag_pos_begin = quick_box_get_pointer_position (quick_box, button->allocation.x + 1, button->allocation.y + 1);
+ quick_box->priv->drag_pos_begin = quick_box_get_drop_position (quick_box, button->allocation.x + 1, button->allocation.y + 1, NULL);
}
Modified: trunk/src/quick-box.h
==============================================================================
--- trunk/src/quick-box.h (original)
+++ trunk/src/quick-box.h Wed Feb 11 17:37:53 2009
@@ -29,6 +29,13 @@
#include "quick-button.h"
#include "quick-separator.h"
+typedef enum {
+ QUICK_DROP_POSITION_BEFORE,
+ QUICK_DROP_POSITION_AFTER,
+ QUICK_DROP_POSITION_INTO_OR_BEFORE,
+ QUICK_DROP_POSITION_INTO_OR_AFTER
+} QuickDropPos;
+
typedef void (*PopulateMenuFunc) (GtkWidget *popup_menu,
GtkWidget *button,
gpointer data);
@@ -57,46 +64,50 @@
GtkWidget * quick_box_new (PanelAppletOrient orient,
int size,
GtkIconTheme *icon_theme);
-void quick_box_set_orient (QuickBox *qbox,
+void quick_box_set_orient (QuickBox *quick_box,
PanelAppletOrient orient);
-PanelAppletOrient quick_box_get_orient (QuickBox *qbox);
-void quick_box_set_size (QuickBox *qbox,
+PanelAppletOrient quick_box_get_orient (QuickBox *quick_box);
+void quick_box_set_size (QuickBox *quick_box,
int size);
-int quick_box_get_size (QuickBox *qbox);
-void quick_box_set_min_visible_cols (QuickBox *qbox,
+int quick_box_get_size (QuickBox *quick_box);
+void quick_box_set_min_visible_cols (QuickBox *quick_box,
int cols);
-int quick_box_get_min_visible_cols (QuickBox *qbox);
-void quick_box_set_max_visible_cols (QuickBox *qbox,
+int quick_box_get_min_visible_cols (QuickBox *quick_box);
+void quick_box_set_max_visible_cols (QuickBox *quick_box,
int cols);
-int quick_box_get_max_visible_cols (QuickBox *qbox);
-void quick_box_set_rows (QuickBox *qbox,
+int quick_box_get_max_visible_cols (QuickBox *quick_box);
+void quick_box_set_rows (QuickBox *quick_box,
int rows);
-int quick_box_get_rows (QuickBox *qbox);
-const int * quick_box_get_size_hint_list (QuickBox *qbox,
+int quick_box_get_rows (QuickBox *quick_box);
+const int * quick_box_get_size_hint_list (QuickBox *quick_box,
int *n_elements);
-void quick_box_reorder_child (QuickBox *qbox,
+void quick_box_reorder_child (QuickBox *quick_box,
GtkWidget *child,
int pos);
-void quick_box_populate_menu_func (QuickBox *qbox,
+void quick_box_populate_menu_func (QuickBox *quick_box,
PopulateMenuFunc pm_func,
gpointer data);
-int quick_box_get_pointer_position (QuickBox *qbox,
+int quick_box_get_pointer_position (QuickBox *quick_box,
int x,
int y);
-GtkWidget * quick_box_add_button (QuickBox *qbox,
+int quick_box_get_drop_position (QuickBox *quick_box,
+ int x,
+ int y,
+ QuickDropPos *drop_position);
+GtkWidget * quick_box_add_button (QuickBox *quick_box,
const char *uri,
int pos);
-GtkWidget * quick_box_add_separator (QuickBox *qbox,
+GtkWidget * quick_box_add_separator (QuickBox *quick_box,
int pos);
-void quick_box_update_child (QuickBox *qbox,
+void quick_box_update_child (QuickBox *quick_box,
QuickButton *child,
GKeyFile *desktop_entry);
-void quick_box_icon_theme_changed (QuickBox *qbox);
-int quick_box_get_child_position (QuickBox *qbox,
+void quick_box_icon_theme_changed (QuickBox *quick_box);
+int quick_box_get_child_position (QuickBox *quick_box,
GtkWidget *child);
-GtkWidget * quick_box_get_child_at_pos (QuickBox *qbox,
+GtkWidget * quick_box_get_child_at_pos (QuickBox *quick_box,
int pos);
-GtkWidget * quick_box_get_child_from_uri (QuickBox *qbox,
+GtkWidget * quick_box_get_child_from_uri (QuickBox *quick_box,
char *uri);
#endif /* QUICK_BOX_H */
Modified: trunk/src/quick-button.c
==============================================================================
--- trunk/src/quick-button.c (original)
+++ trunk/src/quick-button.c Wed Feb 11 17:37:53 2009
@@ -361,7 +361,7 @@
size = widget->allocation.height;
offset = (button->in_button && button->button_down) ? get_displacement (size) : 0;
- if (button->in_button || GTK_WIDGET_HAS_FOCUS (widget))
+ if (button->in_button || quick_button->dnd_highlight || GTK_WIDGET_HAS_FOCUS (widget))
pixbuf = quick_button->scaled_bright;
else
pixbuf = quick_button->scaled;
@@ -387,13 +387,13 @@
GDK_RGB_DITHER_NORMAL,
0, 0);
- if (quick_button->dnd_highlight)
+ /*if (quick_button->dnd_highlight)
gdk_draw_rectangle (widget->window,
widget->style->black_gc, FALSE,
widget->allocation.x,
widget->allocation.y,
widget->allocation.width - 1,
- widget->allocation.height - 1);
+ widget->allocation.height - 1);*/
if (GTK_WIDGET_HAS_FOCUS (widget)) {
int focus_width, focus_pad;
Modified: trunk/src/quick-lounge.c
==============================================================================
--- trunk/src/quick-lounge.c (original)
+++ trunk/src/quick-lounge.c Wed Feb 11 17:37:53 2009
@@ -515,9 +515,6 @@
}
else {
quick_box_add_button (quick_lounge->quick_box, uri, position);
- quick_lounge_save_order (quick_lounge);
- dlg_properties_update (quick_lounge->prop_dialog);
-
launcher_added = TRUE;
}
@@ -564,8 +561,11 @@
return;
}
- if (quick_lounge_add_launcher (edit_data->quick_lounge, desktop_entry, edit_data->position + 1))
+ if (quick_lounge_add_launcher (edit_data->quick_lounge, desktop_entry, edit_data->position + 1)) {
+ quick_lounge_save_order (edit_data->quick_lounge);
+ dlg_properties_update (edit_data->quick_lounge->prop_dialog);
gtk_widget_destroy (GTK_WIDGET (dialog));
+ }
g_key_file_free (desktop_entry);
}
@@ -815,11 +815,13 @@
guint time,
gpointer extra_data)
{
- QuickLounge *quick_lounge = extra_data;
- QuickBox *quick_box = QUICK_BOX (widget);
- GList *list, *scan;
- int pos;
-
+ QuickLounge *quick_lounge = extra_data;
+ QuickBox *quick_box = QUICK_BOX (widget);
+ GList *list, *scan;
+ int pos;
+ QuickDropPos drop_position;
+ gboolean launcher_list_changed = FALSE;
+
if (! ((data->length >= 0) && (data->format == 8))) {
gtk_drag_finish (context, FALSE, FALSE, time);
return;
@@ -827,52 +829,82 @@
gtk_drag_finish (context, TRUE, FALSE, time);
- pos = quick_box_get_pointer_position (quick_box, x, y);
+ pos = quick_box_get_drop_position (quick_box, x, y, &drop_position);
list = get_file_list_from_url_list ((char *) data->data);
- for (scan = list; scan; scan = scan->next) {
- char *src_uri = scan->data;
- char *uri;
- GtkWidget *button;
-
- if (! is_desktop_file (src_uri)) {
+ if ((drop_position == QUICK_DROP_POSITION_INTO_OR_BEFORE)
+ || (drop_position == QUICK_DROP_POSITION_INTO_OR_AFTER))
+ {
+ if (! is_desktop_file (list->data)) {
open_file_list_with_launcher (quick_lounge, pos, list);
+ path_list_free (list);
return;
}
+ }
- uri = g_build_filename (quick_lounge->location,
- file_name_from_path (src_uri),
- NULL);
-
- if (strcmp (src_uri, uri) == 0) {
- button = quick_box_get_child_from_uri (quick_box, uri);
-
- if (button != NULL) {
- int button_pos;
- button_pos = quick_box_get_child_position (quick_box, button);
- if (button_pos != -1)
- quick_box_reorder_child (quick_box, button, pos);
- }
+ if ((drop_position == QUICK_DROP_POSITION_AFTER)
+ || (drop_position == QUICK_DROP_POSITION_INTO_OR_AFTER))
+ {
+ pos++;
+ }
+
+ for (scan = list; scan; scan = scan->next) {
+ char *src_uri = scan->data;
+
+ if (is_desktop_file (src_uri)) {
+ char *uri;
+ GtkWidget *button;
+ uri = g_build_filename (quick_lounge->location,
+ file_name_from_path (src_uri),
+ NULL);
+
+ if (strcmp (src_uri, uri) == 0) {
+ button = quick_box_get_child_from_uri (quick_box, uri);
+
+ if (button != NULL) {
+ int button_pos;
+ button_pos = quick_box_get_child_position (quick_box, button);
+ if (button_pos != -1) {
+ quick_box_reorder_child (quick_box, button, pos);
+ launcher_list_changed = TRUE;
+ }
+ }
+
+ g_free (uri);
+ continue;
+ }
+
g_free (uri);
- continue;
- }
-
- g_free (uri);
- uri = quick_lounge_util__get_unique_uri (quick_lounge);
-
- if (! file_copy (src_uri, uri)) {
+ uri = quick_lounge_util__get_unique_uri (quick_lounge);
+
+ if (! file_copy (src_uri, uri)) {
+ g_free (uri);
+ continue;
+ }
+
+ quick_box_add_button (quick_box, uri, pos++);
+ launcher_list_changed = TRUE;
+
g_free (uri);
- continue;
}
-
- quick_box_add_button (quick_box, uri, ++pos);
- g_free (uri);
+ else {
+ GKeyFile *desktop_entry;
+
+ desktop_entry = _g_desktop_entry_new_for_uri (src_uri);
+ if (quick_lounge_add_launcher (quick_lounge, desktop_entry, pos))
+ launcher_list_changed = TRUE;
+
+ g_key_file_free (desktop_entry);
+ }
+ }
+
+ if (launcher_list_changed) {
+ quick_lounge_save_order (quick_lounge);
+ dlg_properties_update (quick_lounge->prop_dialog);
}
- path_list_free (list);
- quick_lounge_save_order (quick_lounge);
- dlg_properties_update (quick_lounge->prop_dialog);
+ path_list_free (list);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]