[Goodies-commits] r6547 - in xfce4-wmdock-plugin/trunk: panel-plugin po

Andre Ellguth ellguth at xfce.org
Sun Jan 25 20:14:49 CET 2009


Author: ellguth
Date: 2009-01-25 19:14:49 +0000 (Sun, 25 Jan 2009)
New Revision: 6547

Modified:
   xfce4-wmdock-plugin/trunk/panel-plugin/wmdock.c
   xfce4-wmdock-plugin/trunk/po/de.po
   xfce4-wmdock-plugin/trunk/po/fr.po
   xfce4-wmdock-plugin/trunk/po/xfce4-wmdock-plugin.pot
Log:
Added drag & drop support for the dockapps.


Modified: xfce4-wmdock-plugin/trunk/panel-plugin/wmdock.c
===================================================================
--- xfce4-wmdock-plugin/trunk/panel-plugin/wmdock.c	2009-01-25 19:11:01 UTC (rev 6546)
+++ xfce4-wmdock-plugin/trunk/panel-plugin/wmdock.c	2009-01-25 19:14:49 UTC (rev 6547)
@@ -40,13 +40,11 @@
 #include <libxfce4panel/xfce-arrow-button.h>
 #include <libxfce4panel/xfce-panel-convenience.h>
 
-
-
-
 #include "wmdock.h"
 #include "xfce4-wmdock-plugin.xpm"
 #include "tile.xpm"
 
+
 #define DEFAULT_DOCKAPP_WIDTH 64
 #define DEFAULT_DOCKAPP_HEIGHT 64
 #define FONT_WIDTH 4
@@ -54,15 +52,17 @@
 #define WAITCNT_TIMEOUT 1000000
 #define BUF_MAX 4096
 
+#define _BYTE 8
+
 Atom         XfceDockAppAtom;
-GtkWidget    *wmdockIcon = NULL;
-GtkWidget    *btnProperties = NULL;
+GtkWidget    *wmdockIcon     = NULL;
+GtkWidget    *btnProperties  = NULL;
 DockappNode  *dappProperties = NULL;
-GdkPixmap    *gdkPmTile = NULL;
-GdkPixbuf    *gdkPbIcon = NULL;
-WmdockPlugin *wmdock = NULL;
-gchar        **rcCmds = NULL;
-gint         rcCmdcnt = 0;
+GdkPixmap    *gdkPmTile      = NULL;
+GdkPixbuf    *gdkPbIcon      = NULL;
+WmdockPlugin *wmdock         = NULL;
+gchar        **rcCmds        = NULL;
+gint         rcCmdcnt        = 0;
 
 
 /* Properties dialog */
@@ -80,9 +80,18 @@
  GtkWidget *btnMoveUp, *btnMoveDown;
 } prop;
 
+
+static GtkTargetEntry targetList[] = {
+ { "INTEGER", 0, 0 }
+};
+static guint nTargets = G_N_ELEMENTS (targetList);
+
+
 /* Prototypes */
 static void wmdock_properties_dialog_called_from_widget(GtkWidget *, XfcePanelPlugin *);
 static void wmdock_properties_dialog(XfcePanelPlugin *);
+static void wmdock_redraw_dockapp(DockappNode *);
+static void wmdock_destroy_dockapp(DockappNode *);
 
 
 /* #define DEBUG */
@@ -161,6 +170,158 @@
 }
 
 
+static void drag_begin_handl (GtkWidget *widget, GdkDragContext *context,
+			      gpointer dapp)
+{
+ gdkPbIcon = get_icon_from_xpm_scaled((const char **) xfce4_wmdock_plugin_xpm, 
+				      DEFAULT_DOCKAPP_WIDTH/2,
+				      DEFAULT_DOCKAPP_HEIGHT/2);
+
+ gtk_drag_set_icon_pixbuf (context, gdkPbIcon, 0, 0);
+
+ g_object_unref (G_OBJECT(gdkPbIcon)); 
+}
+
+
+static gboolean drag_failed_handl(GtkWidget *widget, GdkDragContext *context,
+				  GtkDragResult result, gpointer dapp)
+{
+ GtkWidget *gtkDlg;
+
+ if(result == GTK_DRAG_RESULT_NO_TARGET && dapp) {
+  gtkDlg = gtk_message_dialog_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (wmdock->plugin))), 
+				  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+				  GTK_MESSAGE_QUESTION,
+				  GTK_BUTTONS_YES_NO,
+				  _("Do you want remove the dockapp \"%s\"?"),
+				  ((DockappNode *) dapp)->name);
+
+  if(gtk_dialog_run (GTK_DIALOG(gtkDlg)) == GTK_RESPONSE_YES)
+   wmdock_destroy_dockapp((DockappNode *) dapp);
+
+  gtk_widget_destroy (GTK_WIDGET(gtkDlg));
+ }
+#ifdef DEBUG
+ fprintf(fp, "Drag failed of dockapp %s\n", ((DockappNode *) dapp)->name);
+ fflush(fp);
+#endif
+
+ return TRUE;
+}
+
+
+static gboolean drag_drop_handl (GtkWidget *widget, GdkDragContext *context,
+				 gint x, gint y, guint time, gpointer dapp)
+{
+ gboolean        is_valid_drop_site;
+ GdkAtom         target_type;
+
+ is_valid_drop_site = TRUE;
+
+ if (context-> targets)
+  {
+   target_type = GDK_POINTER_TO_ATOM
+    (g_list_nth_data (context-> targets, 0));
+
+   gtk_drag_get_data (widget,context, target_type, time);
+  }
+
+ else
+  {
+   is_valid_drop_site = FALSE;
+  }
+
+ return  is_valid_drop_site;
+}
+
+
+
+static void drag_data_received_handl (GtkWidget *widget,
+				      GdkDragContext *context, gint x, gint y,
+				      GtkSelectionData *selection_data,
+				      guint target_type, guint time,
+				      gpointer dapp)
+{
+ glong *_idata;
+ gboolean dnd_success = FALSE;
+ GList *dappsSrc = NULL;
+ GList *dappsDst = NULL;
+
+ if(target_type == 0) {
+  _idata = (glong*) selection_data-> data;
+#ifdef DEBUG  
+  fprintf(fp, "DnD integer received: %ld\n", *_idata);
+  fflush(fp);
+#endif
+  dnd_success = TRUE;
+
+  if(dapp) {
+   dappsSrc = g_list_nth(wmdock->dapps, *_idata);
+   dappsDst = g_list_find(wmdock->dapps, (DockappNode *) dapp);
+
+   if(dappsSrc->data != dappsDst->data) {
+
+#ifdef DEBUG  
+    fprintf(fp, "DnD src dockapp name: %s\n", 
+	    ((DockappNode *) dappsSrc->data)->name);
+    fprintf(fp, "DnD dst dockapp name: %s\n", 
+	    ((DockappNode *) dapp)->name);
+    fflush(fp);
+#endif
+
+    dappsDst->data = dappsSrc->data;
+    dappsSrc->data = dapp;
+
+#ifdef DEBUG  
+    fprintf(fp, "DnD src index: %d\n", 
+	    g_list_index (wmdock->dapps, dappsSrc->data));
+    fprintf(fp, "DnD dst index: %d\n", 
+	    g_list_index (wmdock->dapps, dappsDst->data));
+    fflush(fp);
+#endif
+    
+    gtk_box_reorder_child(GTK_BOX(wmdock->box), 
+			  GTK_WIDGET(((DockappNode *) dappsSrc->data)->tile), 
+			  g_list_index (wmdock->dapps, dappsSrc->data));
+    gtk_box_reorder_child(GTK_BOX(wmdock->box), 
+			  GTK_WIDGET(((DockappNode *) dappsDst->data)->tile), 
+			  g_list_index (wmdock->dapps, dappsDst->data));
+
+    g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);   
+   }
+  }
+
+ }
+
+ gtk_drag_finish (context, dnd_success, FALSE, time);
+
+}
+
+
+
+static void drag_data_get_handl (GtkWidget *widget, GdkDragContext *context,
+				 GtkSelectionData *selection_data, 
+				 guint target_type, guint time, 
+				 gpointer dapp)
+{
+ gint index;
+
+ if(target_type == 0 && dapp) {
+  index = g_list_index (wmdock->dapps, (DockappNode *) dapp);
+
+  gtk_selection_data_set (selection_data, selection_data->target, 
+			  sizeof(index) * _BYTE,
+			  (guchar*) &index, sizeof (index));
+
+#ifdef DEBUG  
+  fprintf(fp, "DnD Integer sent: %ld\n", index);
+  fflush(fp);
+#endif
+ }
+}
+
+
+
 static void wmdock_panel_draw_wmdock_icon (gboolean redraw)
 {
  gdkPbIcon = get_icon_from_xpm_scaled((const char **) xfce4_wmdock_plugin_xpm, 
@@ -253,12 +414,44 @@
 }
 
 
+static void wmdock_setupdnd_dockapp(DockappNode *dapp)
+{
+ /* Make the "well label" a DnD destination. */
+ gtk_drag_dest_set (GTK_WIDGET(dapp->s), GTK_DEST_DEFAULT_MOTION, targetList, 
+		    nTargets, GDK_ACTION_MOVE);
+ 
+ gtk_drag_source_set (GTK_WIDGET(dapp->s), GDK_BUTTON1_MASK, targetList,
+		      nTargets, GDK_ACTION_MOVE);
+
+ g_signal_connect (dapp->s, "drag-begin",
+		   G_CALLBACK (drag_begin_handl), dapp);
+
+ g_signal_connect (dapp->s, "drag-data-get",
+		   G_CALLBACK (drag_data_get_handl), dapp);
+
+ g_signal_connect (dapp->s, "drag-failed",
+		   G_CALLBACK (drag_failed_handl), dapp);
+ 
+ g_signal_connect (dapp->s, "drag-data-received",
+		   G_CALLBACK(drag_data_received_handl), dapp);
+ g_signal_connect (dapp->s, "drag-drop",
+		   G_CALLBACK (drag_drop_handl), dapp);
+
+
+
+#ifdef DEBUG
+ fprintf(fp, "Setup DnD for dockapp %s\n", dapp->name);
+ fflush(fp);
+#endif
+}
+
+
 static void wmdock_destroy_dockapp(DockappNode *dapp)
 {
- #ifdef DEBUG
+#ifdef DEBUG
  fprintf(fp, "Destroy dockapp %s\n", dapp->name);
  fflush(fp);
- #endif
+#endif
  XDestroyWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), dapp->i);
 }
 
@@ -540,10 +733,11 @@
   }
 
   if(rcDapp == FALSE) {
+   XUnmapWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), dapp->i);
+
    dapp->tile = wmdock_create_tile_from_socket(dapp);
 
    gtk_box_pack_start(GTK_BOX(wmdock->box), dapp->tile, FALSE, FALSE, 0);
-
   }
 
   gtk_socket_add_id(dapp->s, dapp->i);
@@ -565,6 +759,9 @@
   if(rcDapp == FALSE)
    wmdock->dapps=g_list_append(wmdock->dapps, dapp);
 
+  /* Test DnD */
+  g_list_foreach(wmdock->dapps, (GFunc)wmdock_setupdnd_dockapp, NULL);
+
   wmdock_refresh_properties_dialog();
  }
 
@@ -1042,9 +1239,7 @@
 			      wmdock->propDispPropButton);
  gtk_toggle_button_set_active((GtkToggleButton *) prop.chkAddOnlyWM, 
 			      wmdock->propDispAddOnlyWM);
- gtk_misc_set_alignment (GTK_MISC (prop.chkDispTile), 0, 0);
- gtk_misc_set_alignment (GTK_MISC (prop.chkPropButton), 0, 0);
- gtk_misc_set_alignment (GTK_MISC (prop.chkAddOnlyWM), 0, 0);
+
  gtk_container_add(GTK_CONTAINER(prop.frmGeneral), prop.vboxGeneral);
  gtk_container_add(GTK_CONTAINER(prop.frmDetect), prop.vboxDetect);
  gtk_box_pack_start (GTK_BOX(prop.vboxGeneral), prop.chkDispTile, 
@@ -1157,7 +1352,8 @@
 	
  /* Configure plugin dialog */
  xfce_panel_plugin_menu_show_configure (plugin);
- g_signal_connect (plugin, "configure-plugin", G_CALLBACK (wmdock_properties_dialog), NULL);
+ g_signal_connect (plugin, "configure-plugin",
+		   G_CALLBACK (wmdock_properties_dialog), NULL);
 	
  /* Read the config file and start the dockapps */
  wmdock_read_rc_file(plugin);

Modified: xfce4-wmdock-plugin/trunk/po/de.po
===================================================================
--- xfce4-wmdock-plugin/trunk/po/de.po	2009-01-25 19:11:01 UTC (rev 6546)
+++ xfce4-wmdock-plugin/trunk/po/de.po	2009-01-25 19:14:49 UTC (rev 6547)
@@ -8,51 +8,56 @@
 "Project-Id-Version: xfce4-wmdock-plugin 0.2.0\n"
 "Report-Msgid-Bugs-To: \n"
 "POT-Creation-Date: 2008-08-24 13:39+0200\n"
-"PO-Revision-Date: 2008-08-17 18:05+0200\n"
+"PO-Revision-Date: 2009-01-25 20:04+0200\n"
 "Last-Translator: Andre Ellguth <ellguth at ibh.de>\n"
 "Language-Team: none <LL at li.org>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: panel-plugin/wmdock.c:219
+#: panel-plugin/wmdock.c:196
+#, c-format
+msgid "Do you want remove the dockapp \"%s\"?"
+msgstr "Soll das Dockapp \"%s\" entfernt werden?"
+
+#: panel-plugin/wmdock.c:397
 msgid "No dockapp is running!"
 msgstr "Kein Dockapp ist gestartet!"
 
-#: panel-plugin/wmdock.c:639
+#: panel-plugin/wmdock.c:855
 #, c-format
 msgid "Failed to start %s!"
 msgstr "Fehler beim Starten von %s!"
 
-#: panel-plugin/wmdock.c:929
+#: panel-plugin/wmdock.c:1145
 msgid "WMdock"
 msgstr ""
 
-#: panel-plugin/wmdock.c:932
+#: panel-plugin/wmdock.c:1148
 msgid "Remove dockapp"
 msgstr "Entferne Dockapp"
 
-#: panel-plugin/wmdock.c:948
+#: panel-plugin/wmdock.c:1164
 msgid "General settings"
 msgstr "Allgemeine Einstellungen"
 
-#: panel-plugin/wmdock.c:949
+#: panel-plugin/wmdock.c:1165
 msgid "Dockapp detection"
 msgstr "Dockapp Erkennung"
 
-#: panel-plugin/wmdock.c:997
+#: panel-plugin/wmdock.c:1213
 msgid "Select dockapp to configure:"
 msgstr "Wähle ein Dockapp:"
 
-#: panel-plugin/wmdock.c:1006
+#: panel-plugin/wmdock.c:1222
 msgid "Shell command:"
 msgstr "Shell Kommando:"
 
-#: panel-plugin/wmdock.c:1017
+#: panel-plugin/wmdock.c:1233
 msgid "Display tile in the background."
 msgstr "Kacheln im Hintergrund darstellen"
 
-#: panel-plugin/wmdock.c:1018
+#: panel-plugin/wmdock.c:1234
 msgid ""
 "Display a separate WMdock properties\n"
 "button in the panel."
@@ -60,7 +65,7 @@
 "Extra Konfigurationsknopf\n"
 "im Panel darstellen"
 
-#: panel-plugin/wmdock.c:1019
+#: panel-plugin/wmdock.c:1235
 msgid ""
 "Add only dockapps which start with\n"
 "wm* in the name."

Modified: xfce4-wmdock-plugin/trunk/po/fr.po
===================================================================
--- xfce4-wmdock-plugin/trunk/po/fr.po	2009-01-25 19:11:01 UTC (rev 6546)
+++ xfce4-wmdock-plugin/trunk/po/fr.po	2009-01-25 19:14:49 UTC (rev 6547)
@@ -62,5 +62,6 @@
 msgid ""
 "Add only dockapps which start with\n"
 "wm* in the name."
-msgstr "Ajoute seulement des dockapps\n"
+msgstr ""
+"Ajoute seulement des dockapps\n"
 "dont des noms commencent avec wm*"

Modified: xfce4-wmdock-plugin/trunk/po/xfce4-wmdock-plugin.pot
===================================================================
--- xfce4-wmdock-plugin/trunk/po/xfce4-wmdock-plugin.pot	2009-01-25 19:11:01 UTC (rev 6546)
+++ xfce4-wmdock-plugin/trunk/po/xfce4-wmdock-plugin.pot	2009-01-25 19:14:49 UTC (rev 6547)
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-08-24 13:39+0200\n"
+"POT-Creation-Date: 2009-01-25 20:01+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
 "Language-Team: LANGUAGE <LL at li.org>\n"
@@ -16,50 +16,55 @@
 "Content-Type: text/plain; charset=CHARSET\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: panel-plugin/wmdock.c:219
+#: panel-plugin/wmdock.c:196
+#, c-format
+msgid "Do you want remove the dockapp \"%s\"?"
+msgstr ""
+
+#: panel-plugin/wmdock.c:397
 msgid "No dockapp is running!"
 msgstr ""
 
-#: panel-plugin/wmdock.c:639
+#: panel-plugin/wmdock.c:855
 #, c-format
 msgid "Failed to start %s!"
 msgstr ""
 
-#: panel-plugin/wmdock.c:929
+#: panel-plugin/wmdock.c:1145
 msgid "WMdock"
 msgstr ""
 
-#: panel-plugin/wmdock.c:932
+#: panel-plugin/wmdock.c:1148
 msgid "Remove dockapp"
 msgstr ""
 
-#: panel-plugin/wmdock.c:948
+#: panel-plugin/wmdock.c:1164
 msgid "General settings"
 msgstr ""
 
-#: panel-plugin/wmdock.c:949
+#: panel-plugin/wmdock.c:1165
 msgid "Dockapp detection"
 msgstr ""
 
-#: panel-plugin/wmdock.c:997
+#: panel-plugin/wmdock.c:1213
 msgid "Select dockapp to configure:"
 msgstr ""
 
-#: panel-plugin/wmdock.c:1006
+#: panel-plugin/wmdock.c:1222
 msgid "Shell command:"
 msgstr ""
 
-#: panel-plugin/wmdock.c:1017
+#: panel-plugin/wmdock.c:1233
 msgid "Display tile in the background."
 msgstr ""
 
-#: panel-plugin/wmdock.c:1018
+#: panel-plugin/wmdock.c:1234
 msgid ""
 "Display a separate WMdock properties\n"
 "button in the panel."
 msgstr ""
 
-#: panel-plugin/wmdock.c:1019
+#: panel-plugin/wmdock.c:1235
 msgid ""
 "Add only dockapps which start with\n"
 "wm* in the name."




More information about the Goodies-commits mailing list