src/give_drag_and_drop.c

Go to the documentation of this file.
00001 /* Give - Statusbar plugin for easy drag & drop data sending via Bluetooth.
00002  * Copyright (C) 2008 Dénes Mátételki
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free
00016  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00029 #include "give_drag_and_drop.h"
00030 #include "give_bluetooth.h"
00031 #include "give_ebook.h"
00032 
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include <sys/stat.h>
00036 
00037 // #include <glib/gprintf.h>
00038 #include <dbus/dbus-glib.h>
00039 
00040 // localization
00041 #include <locale.h>
00042 #include <libintl.h>
00043 #define _(String) gettext(String)
00044 
00045 typedef struct _give_drag_and_drop_private give_drag_and_drop_private;
00046 
00047 #define GIVE_DRAG_AND_DROP_GET_PRIVATE(obj) \
00048                         (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
00049                         GIVE_DRAG_AND_DROP_TYPE, \
00050                         give_drag_and_drop_private));
00051 
00053 struct _give_drag_and_drop_private
00054 {
00055         gboolean bt_is_on;
00057         GtkWidget *destination;
00059         gulong handler_id;
00061         DBusGProxy *dbus_proxy;
00063         give_bluetooth* give_bt_object;
00065         give_ebook *give_ebook_object;
00067 };
00068 
00069 #define TEMP_DIR        "/tmp"
00070 
00074 #define BLUEZ_DBUS_SERVICE      "org.bluez"
00075 #define BLUEZ_DBUS_PATH         "/org/bluez/hci0"
00076 #define BLUEZ_DBUS_INTERFACE    "org.bluez.Adapter"
00077 #define BLUEZ_DBUS_SET_MODE     "SetMode"
00078 #define BLUEZ_DBUS_MESSAGE      "connectable"
00079 
00086 #define PLAIN_TEXT_TYPE         "text/plain"
00087 #define URI_LIST_TYPE           "text/uri-list"
00088 #define CALENDAR_EVENT_TYPE     "application/x-e-calendar-event"
00089 #define CONTACT_LIST_TYPE       "x-osso-contact-list"
00090 
00091 #define TREE_ROW_TYPE           "GTK_TREE_MODEL_ROW"
00092 #define TREE_AS_STRING_TYPE     "text/tree-path-as-string-list"
00093 #define MODEST_EMAIL_TYPE       "text/modest-email"
00094 
00099 enum {
00100         PLAIN_TEXT,
00101         URI_LIST,
00102         CALENDAR_EVENT,
00103         CONTACT_LIST,
00104         TREE_ROW,
00105         TREE_AS_STRING,
00106         MODEST_EMAIL
00107 };
00108 
00118 const GtkTargetEntry drop_types[] =
00119 {
00120         { PLAIN_TEXT_TYPE,      0, PLAIN_TEXT },
00121         { URI_LIST_TYPE,        0, URI_LIST },
00122         { CALENDAR_EVENT_TYPE,  0, CALENDAR_EVENT },
00123         { CONTACT_LIST_TYPE,    0, CONTACT_LIST },
00124         { TREE_ROW_TYPE,        0, TREE_ROW },
00125         { TREE_AS_STRING_TYPE,  0, TREE_AS_STRING },
00126         { MODEST_EMAIL_TYPE,    0, MODEST_EMAIL }
00127 };
00128 
00129 
00130 
00131 // Private funcions
00136 GType give_drag_and_drop_get_type (void);
00137 static void give_drag_and_drop_class_init (give_drag_and_dropClass *klass);
00138 static void give_drag_and_drop_init (give_drag_and_drop *self);
00139 static void give_drag_and_drop_finalize (GObject* self);
00140 
00141 give_drag_and_drop *give_drag_and_drop_new (GtkWidget *widget);
00142 static void give_drag_and_drop_set_dest(give_drag_and_drop *self,
00143                 GtkWidget *widget);
00144 void give_drag_and_drop_have_bt (give_drag_and_drop *self, gboolean setting);
00145 gboolean give_drag_and_drop_turn_bt_on_dialog(give_drag_and_drop *self);
00146 
00147 // Public functions
00153 static GtkWidget *give_drag_and_drop_create_dialog(give_drag_and_drop *self,
00154                 const guint info, const gchar *text, guint *file_count,
00155                 GtkWidget **entry);
00156 static int give_drag_and_drop_run_dialog (give_drag_and_drop *self,
00157                 GtkWidget *dialog, const guint info, const gchar *text,
00158                 const guint file_count, gchar ***files, const GtkWidget *entry);
00159 static void give_drag_and_drop_send(give_drag_and_drop *self, const guint info,
00160                 const gchar *text);
00161 static void give_drag_and_drop_drag_recieved (GtkWidget *widget, 
00162                 GdkDragContext *context, gint x, gint y,
00163                 GtkSelectionData *selection_data, guint info, guint32 time, 
00164                 gpointer user_data);
00165 
00176 GType
00177 give_drag_and_drop_get_type (void)
00178 {
00179         g_message(__PRETTY_FUNCTION__);
00180 
00181         static GType type = 0;
00182         type = g_type_from_name ("give_drag_and_drop");
00183 
00184         if (type == 0){
00185                 static const GTypeInfo info = {
00186                         sizeof (give_drag_and_dropClass),
00187                         (GBaseInitFunc) NULL,
00188                         (GBaseFinalizeFunc) NULL,
00189                         (GClassInitFunc) give_drag_and_drop_class_init,
00190                         NULL,
00191                         NULL,
00192                         sizeof (give_drag_and_drop),
00193                         0,
00194                         (GInstanceInitFunc) give_drag_and_drop_init
00195                 };
00196 
00197                 type = g_type_register_static ( G_TYPE_OBJECT,
00198                                                 "give_drag_and_drop",
00199                                                 &info,
00200                                                 0);
00201 
00202         }
00203 
00204         return type;
00205 }
00206 
00213 static void
00214 give_drag_and_drop_class_init (give_drag_and_dropClass *klass)
00215 {
00216         g_message(__PRETTY_FUNCTION__);
00217 
00218         GObjectClass *object_class;
00219         object_class = (GObjectClass*) klass;
00220 
00221         object_class->finalize  = give_drag_and_drop_finalize;
00222 
00223         g_type_class_add_private (klass, sizeof (give_drag_and_drop_private));
00224 }
00225 
00233 static void
00234 give_drag_and_drop_init (give_drag_and_drop *self)
00235 {
00236         g_message(__PRETTY_FUNCTION__);
00237 
00238         give_drag_and_drop_private *priv;
00239         DBusGConnection *dbus_connection = NULL;
00240         GError *error = NULL;
00241 
00242         g_assert(self);
00243         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00244 
00245         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00246         g_assert (priv);
00247 
00248         dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
00249         if (error){
00250                 g_critical ("%s: Error getting system dbus: %s",
00251                         __PRETTY_FUNCTION__,error->message);
00252                 g_error_free(error);
00253                 g_assert(dbus_connection);
00254         }
00255 
00256         priv->dbus_proxy = dbus_g_proxy_new_for_name(dbus_connection,
00257                                         BLUEZ_DBUS_SERVICE,
00258                                         BLUEZ_DBUS_PATH,
00259                                         BLUEZ_DBUS_INTERFACE);
00260         if (!priv->dbus_proxy){
00261                 g_critical ("%s: Error getting system dbus: %s",
00262                         __PRETTY_FUNCTION__,error->message);
00263                 g_error_free(error);
00264                 g_assert(priv->dbus_proxy);
00265         }
00266 
00267         give_drag_and_drop_have_bt (self, TRUE);
00268 
00269         priv->give_bt_object = give_bluetooth_new();
00270         priv->give_ebook_object = give_ebook_new();
00271 }
00272 
00282 static void
00283 give_drag_and_drop_finalize (GObject* self)
00284 {
00285         g_message(__PRETTY_FUNCTION__);
00286 
00287         give_drag_and_drop_private *priv;
00288 
00289         g_assert(self);
00290         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00291 
00292         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00293         g_assert (priv);
00294 
00295         // free stuff
00296         g_object_unref(G_OBJECT(priv->dbus_proxy));
00297         gtk_drag_dest_unset (priv->destination);
00298 
00299         g_signal_handler_disconnect (priv->destination,
00300                                         priv->handler_id);
00301 
00302         g_object_unref(priv->give_bt_object);
00303         g_object_unref(priv->give_ebook_object);
00304 }
00305 
00313 give_drag_and_drop *
00314 give_drag_and_drop_new (GtkWidget *widget)
00315 {
00316         g_message(__PRETTY_FUNCTION__);
00317 
00318         give_drag_and_drop *give_dnd_object;
00319 
00320         g_assert(widget);
00321 
00322         give_dnd_object = g_object_new(GIVE_DRAG_AND_DROP_TYPE,NULL);
00323         g_assert(give_dnd_object);
00324 
00325         give_drag_and_drop_set_dest(give_dnd_object, widget);
00326 
00327         return give_dnd_object;
00328 }
00329 
00337 static void
00338 give_drag_and_drop_set_dest(give_drag_and_drop *self, GtkWidget *widget)
00339 {
00340         g_message(__PRETTY_FUNCTION__);
00341 
00342         give_drag_and_drop_private *priv;
00343 
00344         g_assert(self);
00345         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00346 
00347         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00348         g_assert (priv);
00349 
00350         g_assert(widget);
00351         priv->destination = widget;
00352 
00353         gtk_drag_dest_set ( priv->destination, GTK_DEST_DEFAULT_ALL,
00354                         drop_types, G_N_ELEMENTS (drop_types),
00355                         GDK_ACTION_COPY);
00356 
00357         priv->handler_id = g_signal_connect(GTK_OBJECT(priv->destination),
00358                         "drag_data_received",
00359                         GTK_SIGNAL_FUNC(give_drag_and_drop_drag_recieved),
00360                         self);
00361 }
00362 
00363 
00370 void
00371 give_drag_and_drop_have_bt (give_drag_and_drop *self, gboolean setting)
00372 {
00373         g_message(__PRETTY_FUNCTION__);
00374 
00375         give_drag_and_drop_private *priv;
00376 
00377         g_assert(self);
00378         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00379 
00380         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00381         g_assert (priv);
00382 
00383         priv->bt_is_on = setting;
00384 }
00385 
00404 static GtkWidget *
00405 give_drag_and_drop_create_dialog(give_drag_and_drop *self, const guint info,
00406                         const gchar *text, guint *file_count, GtkWidget **entry)
00407 {
00408         g_message(__PRETTY_FUNCTION__);
00409 
00410         GtkWidget *dialog;
00411         gchar dialog_label[20];
00412         GtkWidget *dialog_message;
00413         GtkWidget *vbox;
00414 
00415         gchar *s;       // temp string to iterate the filenames in 'text'
00416 
00417         gchar *file;    // one full-path file item of 'text'
00418         gchar *filenames = NULL;        // list of filenames (without path) 
00419                                         // seperated with '\n'
00420 
00421         gchar *contact;         // id of a conatact in EDS
00422         gchar *contacts;        // full names of selected contacts
00423 
00424         struct stat st;
00425         gboolean dir_selected = FALSE;
00426         gchar *summary;
00427 
00428         give_drag_and_drop_private *priv;
00429 
00430         g_assert(self);
00431         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00432 
00433         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00434         g_assert (priv);
00435 
00436         g_assert(text);
00437 
00438         switch ( info ){
00439                 case PLAIN_TEXT:
00440                         sprintf(dialog_label,_("Give text as:"));
00441                         dialog_message = gtk_entry_new ();
00442                         *entry = dialog_message;
00443                         gtk_entry_set_text ( GTK_ENTRY(dialog_message),
00444                                                 "note.txt");
00445                         break;
00446 
00447                 case CALENDAR_EVENT:
00448                         sprintf(dialog_label,_("Give event as:"));
00449                         dialog_message = gtk_entry_new ();
00450                         *entry = dialog_message;
00451 
00452                         summary = (gchar *) calloc (
00453                                         strlen ( strstr ( text, "SUMMARY:" ))
00454                                         - strlen ( strstr( text, "UID" )) - 4,
00455                                         sizeof( gchar));
00456 
00457                         strncpy ( summary, strstr ( text, "SUMMARY:" )+8,
00458                                         strlen ( strstr ( text, "SUMMARY:" ))
00459                                         - strlen ( strstr( text, "UID" )) - 9);
00460 
00461                         strcat ( summary, ".vcs");
00462 
00463                         gtk_entry_set_text ( GTK_ENTRY(dialog_message),
00464                                                 summary);
00465 
00466                         break;
00467 
00468                 case URI_LIST:
00469 
00470                         sprintf(dialog_label,_("Give file(s):"));
00471                         filenames = NULL;
00472                         *file_count = 0;
00473                         // since text contains full paths, filenames can be
00474                         // just shorter
00475                         filenames = (gchar *) calloc ( strlen (text),
00476                                                         sizeof (gchar ));
00477 
00478                         for (   s = (gchar *)text;
00479                                 s != NULL && strlen(s) != 0;
00480                                 s = strstr( s, "\n") != NULL  ? s + strlen (s) -
00481                                         strlen ( strstr( s, "\n")) + 1: NULL)
00482                         {
00483                                 file = g_strndup ( s, strlen ( s ) -
00484                                                 (strstr( s, "\n") == NULL ? 0 :
00485                                                 strlen ( strstr( s, "\n"))+1) );
00486 
00487                                 stat (file+7, &st);
00488                                 if ( S_ISDIR( st.st_mode) ) {
00489                                         dir_selected = TRUE;
00490                                         break;
00491                                 }
00492 
00493                                 strcat (filenames, "\n");
00494                                 strcat (filenames, g_strrstr( file, "/")+1 );
00495 
00496 
00497                                 (*file_count)++;
00498                                 g_free(file);
00499                         }
00500 
00501                         dialog_message = gtk_label_new (filenames+1);
00502                         break;
00503 
00504                 case CONTACT_LIST:
00505 
00506                         sprintf(dialog_label,_("Give contact(s):"));
00507                         contacts = (gchar *) calloc ( 1000,
00508                                                         sizeof (gchar ));
00509                         *file_count = 0; // contact count this time
00510 
00511 
00512                         for (   s = (gchar *)text;
00513                                 s != NULL && strlen(s) != 0;
00514                                 s = strstr( s, "\n") != NULL  ? s + strlen (s) -
00515                                         strlen ( strstr( s, "\n")) + 1: NULL)
00516                         {
00517                                 contact = g_strndup ( s, strlen ( s ) -
00518                                                 (strstr( s, "\n") == NULL ? 0 :
00519                                                 strlen ( strstr( s, "\n"))) );
00520 
00521                                 strcat (contacts, "\n");
00522                                 strcat (contacts, give_ebook_get_contact_name(
00523                                                         priv->give_ebook_object,
00524                                                         contact));
00525                                 strcat (contacts, ".vcf");
00526 
00527                                 (*file_count)++;
00528                         }
00529 
00530                         dialog_message = gtk_label_new (contacts+1);
00531                         break;
00532 
00533                 default:
00534                         dialog_message = NULL;
00535                         g_assert(0);
00536                         break;
00537         }
00538 
00539 
00540         if ( dir_selected ){
00541 
00542                 dialog = gtk_dialog_new_with_buttons (
00543                                         _("Give directory"),
00544                                         NULL,
00545                                         GTK_DIALOG_MODAL,
00546                                         GTK_STOCK_OK, GTK_RESPONSE_REJECT,
00547                                         NULL);
00548 
00549                 dialog_message = gtk_label_new
00550                                         (_("Directories cannot be selected"));
00551 
00552         } else {
00553 
00554                 dialog = gtk_dialog_new_with_buttons (
00555                                         dialog_label,
00556                                         NULL,
00557                                         GTK_DIALOG_MODAL,
00558                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
00559                                         GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
00560                                         NULL);
00561         }
00562 
00563         gtk_label_set_justify(GTK_LABEL(dialog_message), GTK_JUSTIFY_CENTER );
00564 
00565         vbox = gtk_vbox_new(FALSE, 5);
00566         gtk_container_add (GTK_CONTAINER (vbox), dialog_message);
00567         gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), vbox);
00568 
00569         return dialog;
00570 }
00571 
00590 static gint
00591 give_drag_and_drop_run_dialog ( give_drag_and_drop      *self,
00592                                 GtkWidget               *dialog,
00593                                 const guint             info,
00594                                 const gchar             *text,
00595                                 const guint             file_count,
00596                                 gchar                   ***files,
00597                                 const GtkWidget         *entry)
00598 {
00599         g_message(__PRETTY_FUNCTION__);
00600 
00601         guint result;
00602         gchar *s;       // temp string to iterate the filenames in 'text'
00603         gchar *file;    // one full-path file item of 'text'
00604         gchar *filenames;// list of filenames (without path) seperated with '\n'
00605         gchar *contact;
00606         FILE *fp;
00607         gint retval;
00608         gint i;
00609         give_drag_and_drop_private *priv;
00610 
00611         g_assert(self);
00612         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00613 
00614         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00615         g_assert (priv);
00616 
00617         g_assert (dialog);
00618         g_assert (text);
00619 
00620         gtk_widget_show_all ( dialog);
00621         result = gtk_dialog_run ( GTK_DIALOG ( dialog));
00622 
00623         if ( result == GTK_RESPONSE_REJECT){
00624                 retval = 0;
00625                 gtk_widget_destroy (dialog);
00626                 return retval;
00627         }
00628 
00629         // else result is GTK_RESPONSE_ACCEPT
00630         switch ( info ) {
00631 
00632                 case PLAIN_TEXT: 
00633                 case CALENDAR_EVENT:
00634 
00635                         g_assert (entry);
00636 
00637                         filenames = g_strdup_printf( "%s/%s",TEMP_DIR,
00638                                         gtk_entry_get_text( GTK_ENTRY(entry)));
00639 
00640                         fp = fopen(filenames,"w");
00641                         g_assert(fp);
00642 
00643                         if ( info == PLAIN_TEXT)
00644                                 fprintf(fp,"%s",text);
00645                         else 
00646                                 fprintf(fp,"BEGIN:VCALENDAR\nVERSION:2.0\n"
00647                                         "%s\nEND:VCALENDAR",text);
00648                         
00649                         fclose(fp);
00650 
00651                         *files = g_new0(gchar*, 2);
00652                         (*files)[0] = filenames;
00653                         (*files)[1] = NULL;
00654 
00655                         g_debug("%s - filenames: '%s'",__PRETTY_FUNCTION__,
00656                                                                 (*files)[0]);
00657 
00658 
00659                         break;
00660 
00661                 case URI_LIST:
00662 
00663                         g_assert (file_count > 0);
00664 
00665                         *files = g_new0(gchar*, file_count);
00666                         i = 0;
00667 
00668                         for (   s = (gchar *)text;
00669                                 s != NULL && strlen(s) != 0;
00670                                 s = strstr( s, "\n") != NULL  ? s + strlen (s) -
00671                                         strlen ( strstr( s, "\n")) + 1: NULL)
00672                         {
00673                                 file = g_strndup ( s, strlen ( s ) -
00674                                                 (strstr( s, "\n") == NULL ? 0 :
00675                                                 strlen ( strstr( s, "\n"))+1) );
00676 
00677                                 (*files)[i++] = file;
00678                         }
00679                         (*files)[file_count] = NULL;
00680 
00681                         break;
00682 
00683 
00684                 case CONTACT_LIST:
00685 
00686                         g_assert (file_count > 0);
00687 
00688                         *files = g_new0(gchar*, file_count);
00689                         i = 0;
00690 
00691                         for (   s = (gchar *)text;
00692                                 s != NULL && strlen(s) != 0;
00693                                 s = strstr( s, "\n") != NULL  ? s + strlen (s) -
00694                                         strlen ( strstr( s, "\n")) + 1: NULL)
00695                         {
00696                                 contact = g_strndup ( s, strlen ( s ) -
00697                                                 (strstr( s, "\n") == NULL ? 0 :
00698                                                 strlen ( strstr( s, "\n"))) );
00699 
00700                                 filenames = g_strdup_printf( "%s/%s.vcf",
00701                                         TEMP_DIR, give_ebook_get_contact_name(
00702                                                         priv->give_ebook_object,
00703                                                         contact));
00704 
00705                                 fp = fopen(filenames,"w");
00706                                 g_assert(fp);
00707 
00708                                 fprintf(fp,"%s",give_ebook_get_contact_vcard(
00709                                                         priv->give_ebook_object,
00710                                                         contact));
00711                                 fclose(fp);
00712 
00713                                 (*files)[i++] = filenames;
00714 
00715                         }
00716                         (*files)[file_count] = NULL;
00717 
00718                         break;
00719 
00720                 default:
00721                         *files = NULL;
00722                         g_assert(0);
00723                         break;
00724         }
00725 
00726         gtk_widget_destroy (dialog);
00727         return 1;
00728 }
00729 
00740 static void
00741 give_drag_and_drop_send(give_drag_and_drop *self, const guint info, 
00742                         const gchar *text)
00743 {
00744         g_message(__PRETTY_FUNCTION__);
00745 
00746         give_drag_and_drop_private *priv;
00747         GtkWidget *dialog;
00748         GtkWidget *entry;
00749         gchar **files;
00750         guint file_count;
00751 
00752         g_assert(self);
00753         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00754 
00755         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00756         g_assert (priv);
00757 
00758         g_assert(text);
00759 
00760         dialog = give_drag_and_drop_create_dialog(self, info, text, &file_count, 
00761                                                         &entry);
00762         if ( give_drag_and_drop_run_dialog(self, dialog, info, text, file_count, 
00763                                                 &files, entry) == 1){
00764 
00765                 give_bluetooth_send_file(priv->give_bt_object, files);
00766 
00768                 g_strfreev (files);
00769         }
00770 }
00771 
00772 
00777 gboolean
00778 give_drag_and_drop_turn_bt_on_dialog(give_drag_and_drop *self)
00779 {
00780         g_message(__PRETTY_FUNCTION__);
00781 
00782         GtkWidget *dialog;
00783         GtkWidget *label;
00784         gint result;
00785         gboolean turned_on;
00786         give_drag_and_drop_private *priv;
00787         GError *error = NULL;
00788 
00789         g_assert(self);
00790         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00791 
00792         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00793         g_assert (priv);
00794 
00795         dialog = gtk_dialog_new_with_buttons (
00796                                         "Give",
00797                                         NULL,
00798                                         GTK_DIALOG_MODAL,
00799                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
00800                                         GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
00801                                         NULL);
00802 
00803 
00804         label = gtk_label_new (_("Bluetooth is off.\nTurn it on?"));
00805 
00806         gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
00807         gtk_widget_show_all (dialog);
00808 
00809         result = gtk_dialog_run (GTK_DIALOG (dialog));
00810         switch (result){
00811                 case GTK_RESPONSE_ACCEPT:
00812 
00813                         if (!dbus_g_proxy_call(priv->dbus_proxy,
00814                                 BLUEZ_DBUS_SET_MODE, &error,
00815                                 G_TYPE_STRING, BLUEZ_DBUS_MESSAGE,
00816                                 G_TYPE_INVALID, G_TYPE_INVALID))
00817                         {
00818                                 g_warning("%s: Error sending %s request "
00819                                                 "to bluez: %s",
00820                                         __PRETTY_FUNCTION__,BLUEZ_DBUS_SET_MODE,
00821                                         error->message);
00822                                 g_error_free(error);
00823                                 turned_on = FALSE;
00824                         } else {
00825                                 turned_on = TRUE;
00826                         }
00827 
00828                         break;
00829                 case GTK_RESPONSE_REJECT:
00830                         // do nothing
00831                         turned_on = FALSE;
00832                         break;
00833                 default:
00834                         g_assert(0);
00835         }
00836 
00837         gtk_widget_destroy (dialog);
00838         return turned_on;       
00839 }
00840 
00855 static void
00856 give_drag_and_drop_drag_recieved
00857                         (GtkWidget              *widget,
00858                         GdkDragContext          *context,
00859                         gint                    x,
00860                         gint                    y,
00861                         GtkSelectionData        *selection_data,
00862                         guint                   info,
00863                         guint32                 time,
00864                         gpointer                user_data)
00865 {
00866         g_message(__PRETTY_FUNCTION__);
00867 
00868         g_assert(widget);
00869         g_assert(context);
00870         g_assert(selection_data);
00871         g_assert(user_data);
00872 
00873         give_drag_and_drop *self;
00874         give_drag_and_drop_private *priv;
00875 
00876         self = (give_drag_and_drop *) user_data;
00877         g_assert(self);
00878         g_assert(GIVE_DRAG_AND_DROP_IS_OBJECT(self));
00879 
00880         priv = GIVE_DRAG_AND_DROP_GET_PRIVATE (self);
00881         g_assert (priv);
00882 
00883         // otherwise the function will be invoked multiple times
00884         g_signal_stop_emission_by_name (widget, "drag_data_received");
00885 
00886         // if BT is off, then invoke 'turn-on BT' dialog
00887         if ( !priv->bt_is_on  )         
00888                 if ( !give_drag_and_drop_turn_bt_on_dialog(self) ) 
00889                         return;
00890 
00891         g_debug("%s: got data. info: %d, data: '%s'",__PRETTY_FUNCTION__,
00892                 info, selection_data->data);
00893 
00894         // modest-patch  is under development, ignore data from modest.
00895         if (    info == MODEST_EMAIL)
00896                         g_message("%s: my modest :)",__PRETTY_FUNCTION__);
00897         if (    info == TREE_ROW ||
00898                 info == TREE_AS_STRING ||
00899                 info == MODEST_EMAIL
00900                 ) return;
00901 
00902         give_drag_and_drop_send(self, info, selection_data->data);
00903 
00906 //      g_free(selection_data);
00907 }

Generated on Sat May 17 16:27:32 2008 for Give by  doxygen 1.5.3