Exemplo n.º 1
0
bool ClipboardGtk::setData(const String& typeString, const String& data)
{
    if (policy() != ClipboardWritable)
        return false;

    bool success = false;
    ClipboardType type = dataObjectTypeFromHTMLClipboardType(typeString);
    if (type == ClipboardTypeURIList || type == ClipboardTypeURL) {
        Vector<KURL> uriList;
        gchar** uris = g_uri_list_extract_uris(data.utf8().data());
        if (uris) {
            gchar** currentURI = uris;
            while (*currentURI) {
                uriList.append(KURL(KURL(), *currentURI));
                currentURI++;
            }
            g_strfreev(uris);
            m_dataObject->setURIList(uriList);
            success = true;
        }
    } else if (type == ClipboardTypeMarkup) {
        m_dataObject->setMarkup(data);
        success = true;
    } else if (type == ClipboardTypeText) {
        m_dataObject->setText(data);
        success = true;
    }

    if (success && m_clipboard)
        m_helper->writeClipboardContents(m_clipboard);

    return success;
}
static void
theme_drag_data_received_cb (GtkWidget *widget,
                             GdkDragContext *context,
                             gint x, gint y,
                             GtkSelectionData *selection_data,
                             guint info, guint time,
                             AppearanceData *data)
{
  gchar **uris;

  if (!(info == TARGET_URI_LIST || info == TARGET_NS_URL))
    return;

  uris = g_uri_list_extract_uris ((gchar *) gtk_selection_data_get_data (selection_data));

  if (uris != NULL && uris[0] != NULL) {
    GFile *f = g_file_new_for_uri (uris[0]);

    mate_theme_install (f,
        GTK_WINDOW (appearance_capplet_get_widget (data, "appearance_window")));
    g_object_unref (f);
  }

  g_strfreev (uris);
}
Exemplo n.º 3
0
static jobject dnd_target_get_list(JNIEnv *env, gboolean files)
{
    jobject result = NULL;
    selection_data_ctx ctx;

    if (dnd_target_receive_data(env, TARGET_MIME_URI_LIST_ATOM, &ctx)) {
        result = uris_to_java(env, g_uri_list_extract_uris((gchar *)ctx.data), files);
        g_free(ctx.data);
    }
    
    return result;
}
Exemplo n.º 4
0
jobjectArray dnd_target_get_mimes(JNIEnv *env)
{
    if (check_state_in_drag(env)) {
        return NULL;
    }
    if (!enter_ctx.mimes) {
        GList* targets = GLASS_GDK_DRAG_CONTEXT_LIST_TARGETS(enter_ctx.ctx);
        jobject set = env->NewObject(jHashSetCls, jHashSetInit, NULL);

        while (targets) {
            GdkAtom target = GDK_POINTER_TO_ATOM(targets->data);
            gchar *name = gdk_atom_name(target);

            if (target_is_text(target)) {
                env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("text/plain"), NULL);
            }

            if (target_is_image(target)) {
                env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("application/x-java-rawimage"), NULL);
            }

            if (target_is_uri(target)) {
                selection_data_ctx ctx;
                if (dnd_target_receive_data(env, TARGET_MIME_URI_LIST_ATOM, &ctx)) {
                    gchar** uris = g_uri_list_extract_uris((gchar *) ctx.data);
                    guint size = g_strv_length(uris);
                    guint files_cnt = get_files_count(uris);
                    if (files_cnt) {
                        env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("application/x-java-file-list"), NULL);
                    }
                    if (size - files_cnt) {
                        env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("text/uri-list"), NULL);
                    }
                    g_strfreev(uris);
                }
                g_free(ctx.data);
            } else {
                env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF(name), NULL);
            }

            g_free(name);
            targets = targets->next;
        }
        enter_ctx.mimes = env->NewObjectArray(env->CallIntMethod(set, jSetSize, NULL),
                jStringCls, NULL);
        enter_ctx.mimes = (jobjectArray)env->CallObjectMethod(set, jSetToArray, enter_ctx.mimes, NULL);
        enter_ctx.mimes = (jobjectArray)env->NewGlobalRef(enter_ctx.mimes);
    }
    return enter_ctx.mimes;
}
Exemplo n.º 5
0
static void remmina_main_on_drag_data_received(RemminaMain *remminamain, GdkDragContext *drag_context, gint x, gint y,
		GtkSelectionData *data, guint info, guint time, gpointer user_data)
{
	gchar **uris;
	GSList *files = NULL;
	gint i;

	uris = g_uri_list_extract_uris((const gchar *) gtk_selection_data_get_data(data));
	for (i = 0; uris[i]; i++)
	{
		if (strncmp(uris[i], "file://", 7) != 0)
			continue;
		files = g_slist_append(files, g_strdup(uris[i] + 7));
	}
	g_strfreev(uris);
	remmina_main_import_file_list(remminamain, files);
}
Exemplo n.º 6
0
static void
entry_drag_data_received (GtkEditable      *entry,
			  GdkDragContext   *context,
			  gint              x,
			  gint              y,
			  GtkSelectionData *selection_data,
			  guint             info,
			  guint32           time,
			  PanelRunDialog   *dialog)
{
	char **uris;
	char  *file;
	int    i;

        if (gtk_selection_data_get_format (selection_data) != 8 || gtk_selection_data_get_length (selection_data) == 0) {
        	g_warning (_("URI list dropped on run dialog had wrong format (%d) or length (%d)\n"),
			   gtk_selection_data_get_format (selection_data),
			   gtk_selection_data_get_length (selection_data));
		return;
        }

	uris = g_uri_list_extract_uris ((const char *)gtk_selection_data_get_data (selection_data));

	if (!uris) {
		gtk_drag_finish (context, FALSE, FALSE, time);
		return;
	}

	for (i = 0; uris [i]; i++) {
		if (!uris [i] || !uris [i][0])
			continue;

		file = g_filename_from_uri (uris [i], NULL, NULL);

		/* FIXME: I assume the file is in utf8 encoding if coming from a URI? */
		if (file) {
			panel_run_dialog_append_file_utf8 (dialog, file);
			g_free (file);
		} else
			panel_run_dialog_append_file_utf8 (dialog, uris [i]);
	}

	g_strfreev (uris);
	gtk_drag_finish (context, TRUE, FALSE, time);
}
Exemplo n.º 7
0
GList *
pragha_dnd_library_get_mobj_list (GtkSelectionData *data, PraghaDatabase *cdbase)
{
	gint n = 0, location_id = 0;
	gchar *name = NULL, *uri, **uris;
	PraghaMusicobject *mobj = NULL;
	GList *list = NULL;

	CDEBUG(DBG_VERBOSE, "Dnd: Library");

	uris = g_uri_list_extract_uris ((const gchar *) gtk_selection_data_get_data (data));
	if (!uris) {
		g_warning("No selections to process in DnD");
		return list;
	}

	/* Dnd from the library, so will read everything from database. */

	pragha_database_begin_transaction (cdbase);

	/* Get the mobjs from the path of the library. */

	for (n = 0; uris[n] != NULL; n++) {
		uri = uris[n];
		if (g_str_has_prefix(uri, "Location:/")) {
			location_id = atoi(uri + strlen("Location:/"));
			mobj = new_musicobject_from_db (cdbase, location_id);
			if (G_LIKELY(mobj))
				list = g_list_prepend(list, mobj);
		}
		else if(g_str_has_prefix(uri, "Playlist:/")) {
			name = uri + strlen("Playlist:/");
			list = add_playlist_to_mobj_list (cdbase, name, list);
		}
		else if(g_str_has_prefix(uri, "Radio:/")) {
			name = uri + strlen("Radio:/");
			list = add_radio_to_mobj_list (cdbase, name, list);
		}
	}
	pragha_database_commit_transaction (cdbase);

	g_strfreev(uris);

	return g_list_reverse (list);
}
static void
wp_drag_received (GtkWidget *widget,
                  GdkDragContext *context,
                  gint x, gint y,
                  GtkSelectionData *selection_data,
                  guint info, guint time,
                  AppearanceData *data)
{
  if (info == TARGET_URI_LIST || info == TARGET_BGIMAGE)
  {
    GSList *realuris = NULL;
    gchar **uris;

    uris = g_uri_list_extract_uris ((gchar *) gtk_selection_data_get_data (selection_data));
    if (uris != NULL)
    {
      GtkWidget *w;
      GdkWindow *window;
      GdkCursor *cursor;
      gchar **uri;

      w = appearance_capplet_get_widget (data, "appearance_window");
      window = gtk_widget_get_window (w);

      cursor = gdk_cursor_new_for_display (gdk_display_get_default (),
             GDK_WATCH);
      gdk_window_set_cursor (window, cursor);
      gdk_cursor_unref (cursor);

      for (uri = uris; *uri; ++uri)
      {
        GFile *f;

        f = g_file_new_for_uri (*uri);
        realuris = g_slist_append (realuris, g_file_get_path (f));
        g_object_unref (f);
      }

      wp_add_images (data, realuris);
      gdk_window_set_cursor (window, NULL);

      g_strfreev (uris);
    }
  }
}
Exemplo n.º 9
0
GSList*
eog_util_parse_uri_string_list_to_file_list (const gchar *uri_list)
{
	GSList* file_list = NULL;
	gsize i = 0;
	gchar **uris;

	uris = g_uri_list_extract_uris (uri_list);

	while (uris[i] != NULL) {
		file_list = g_slist_append (file_list, g_file_new_for_uri (uris[i]));
		i++;
	}

	g_strfreev (uris);

	return file_list;
}
Exemplo n.º 10
0
static void gtkDropFileDragDataReceived(GtkWidget* w, GdkDragContext* context, int x, int y,
                                        GtkSelectionData* seldata, guint info, guint time, Ihandle* ih)
{
  gchar **uris = NULL, *data = NULL;
  int i, count;

  IFnsiii cb = (IFnsiii)IupGetCallback(ih, "DROPFILES_CB");
  if (!cb) return; 

#if GTK_CHECK_VERSION(2, 6, 0)
#if GTK_CHECK_VERSION(2, 14, 0)
  data = (char*)gtk_selection_data_get_data(seldata);
#else
  data = (char*)seldata->data;
#endif
  uris = g_uri_list_extract_uris(data);
#endif

  if (!uris)
    return;

  count = 0;
  while (uris[count])
    count++;

  for (i=0; i<count; i++)
  {
    char* filename = uris[i];
    if (iupStrEqualPartial(filename, "file://"))
    {
      filename += strlen("file://");
      if (filename[2] == ':')  /* in Windows there is an extra '/' at the beginning. */
        filename++;
    }
    if (cb(ih, filename, count-i-1, x, y) == IUP_IGNORE)
      break;
  }

  g_strfreev (uris);
  (void)time;
  (void)info;
  (void)w;
  (void)context;
}
Exemplo n.º 11
0
static void
drag_data_received_cb (GtkWidget        *widget,
		       GdkDragContext   *context,
		       gint              x,
		       gint              y,
		       GtkSelectionData *selection_data,
		       guint             info,
		       guint             time,
		       Launcher         *launcher)
{
	GError  *error = NULL;
	char   **uris;
	int      i;
	GList   *file_list;

	launcher_do_zoom_animation (widget);
	
	file_list = NULL;
	uris = g_uri_list_extract_uris ((const char *) gtk_selection_data_get_data (selection_data));
	for (i = 0; uris[i]; i++)
		file_list = g_list_prepend (file_list, uris[i]);
	file_list = g_list_reverse (file_list);

	panel_launch_key_file (launcher->key_file, file_list,
			       launcher_get_screen (launcher), &error);

	g_list_free (file_list);
	g_strfreev (uris);

	if (error) {
		GtkWidget *error_dialog;
		error_dialog = panel_error_dialog (NULL,
						   launcher_get_screen (launcher),
						   "cannot_use_dropped_item",
						   TRUE,
						   _("Could not use dropped item"),
						   error->message);
		launcher_register_error_dialog (launcher, error_dialog);
		g_clear_error (&error);
	}

	gtk_drag_finish (context, TRUE, FALSE, time);
}
Exemplo n.º 12
0
/* modified version of eog's
 * eog_util_parse_uri_string_list_to_file_list */
GSList*
vnr_tools_parse_uri_string_list_to_file_list (const gchar *uri_list)
{
    GSList* file_list = NULL;
    gsize i = 0;
    gchar **uris;
    gchar* current_path;

    uris = g_uri_list_extract_uris (uri_list);

    while (uris[i] != NULL) {
        current_path = g_file_get_path (g_file_new_for_uri(uris[i]));
        if(current_path != NULL)
            file_list = g_slist_append (file_list, current_path);
        i++;
    }

    g_strfreev (uris);
    return g_slist_reverse (file_list);
}
Exemplo n.º 13
0
void
gnac_profiles_mgr_on_drag_data_received(GtkWidget        *widget,
                                        GdkDragContext   *context,
                                        gint              x,
                                        gint              y,
                                        GtkSelectionData *selection_data,
                                        guint             info,
                                        guint             time,
                                        gpointer          data)
{
  gchar **uris = g_uri_list_extract_uris((const gchar *)
      gtk_selection_data_get_data(selection_data));
  if (!uris) {
    gtk_drag_finish(context, FALSE, FALSE, time);
    return;
  }

  ThreadCopyData  *tcopy_data = g_malloc(sizeof(ThreadCopyData));
  tcopy_data->uris = uris;
  tcopy_data->info = info;

  GError *error = NULL;

#if GLIB_CHECK_VERSION(2, 31, 0)
  g_thread_try_new("drag-data-thread",
      (GThreadFunc) gnac_profiles_mgr_copy_and_load_files, tcopy_data, &error);
#else
  g_thread_create((GThreadFunc) gnac_profiles_mgr_copy_and_load_files,
      tcopy_data, TRUE, &error);
#endif
  if (error) {
    libgnac_debug("Failed to create thread: %s", error->message);
    gnac_profiles_mgr_display_status_message(NULL,
        _("Impossible to import file(s)"));
    g_clear_error(&error);
  }

  gtk_drag_finish(context, TRUE, FALSE, time);
}
Exemplo n.º 14
0
void ptk_clipboard_paste_links( GtkWindow* parent_win,
                                const char* dest_dir,
                                GtkTreeView* task_view )   //MOD added
{
    GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD );
    GdkAtom gnome_target;
    GdkAtom uri_list_target;
    gchar **uri_list, **puri;
    GtkSelectionData* sel_data = NULL;
    GList* files = NULL;
    gchar* file_path;

    PtkFileTask* task;
    VFSFileTaskType action;
    char* uri_list_str;

    gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE );
    sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target );
    if ( sel_data )
    {
        if ( sel_data->length <= 0 || sel_data->format != 8 )
            return ;

        uri_list_str = ( char* ) sel_data->data;
        action = VFS_FILE_TASK_LINK;
        if ( uri_list_str )
        {
            while ( *uri_list_str && *uri_list_str != '\n' )
                ++uri_list_str;
        }
    }
    else
    {
        uri_list_target = gdk_atom_intern( "text/uri-list", FALSE );
        sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target );
        if ( ! sel_data )
            return ;
        if ( sel_data->length <= 0 || sel_data->format != 8 )
            return ;
        uri_list_str = ( char* ) sel_data->data;
        action = VFS_FILE_TASK_LINK;
    }

    if ( uri_list_str )
    {
        puri = uri_list = g_uri_list_extract_uris( uri_list_str );
        while ( *puri )
        {
            if ( file_path = g_filename_from_uri( *puri, NULL, NULL ) )
                files = g_list_prepend( files, file_path );
            ++puri;
        }
        g_strfreev( uri_list );
        gtk_selection_data_free( sel_data );

        //sfm
        if ( files )
            files = g_list_reverse( files );

        task = ptk_file_task_new( action,
                                  files,
                                  dest_dir,
                                  GTK_WINDOW( parent_win ),
                                  GTK_WIDGET( task_view ) );
        ptk_file_task_run( task );
    }
}
Exemplo n.º 15
0
void ptk_clipboard_paste_files( GtkWindow* parent_win,
                                const char* dest_dir, GtkTreeView* task_view )
{
    GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD );
    GdkAtom gnome_target;
    GdkAtom uri_list_target;
    gchar **uri_list, **puri;
    GtkSelectionData* sel_data = NULL;
    GList* files = NULL;
    gchar* file_path;

    PtkFileTask* task;
    VFSFileTaskType action;
    char* uri_list_str;

    gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE );
    sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target );
    if ( sel_data )
    {
        if ( sel_data->length <= 0 || sel_data->format != 8 )
            return ;

        uri_list_str = ( char* ) sel_data->data;
        if ( 0 == strncmp( ( char* ) sel_data->data, "cut", 3 ) )
            action = VFS_FILE_TASK_MOVE;
        else
            action = VFS_FILE_TASK_COPY;

        if ( uri_list_str )
        {
            while ( *uri_list_str && *uri_list_str != '\n' )
                ++uri_list_str;
        }
    }
    else
    {
        uri_list_target = gdk_atom_intern( "text/uri-list", FALSE );
        sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target );
        if ( ! sel_data )
            return ;
        if ( sel_data->length <= 0 || sel_data->format != 8 )
            return ;
        uri_list_str = ( char* ) sel_data->data;

        if ( clipboard_action == GDK_ACTION_MOVE )
            action = VFS_FILE_TASK_MOVE;
        else
            action = VFS_FILE_TASK_COPY;
    }

    if ( uri_list_str )
    {
        puri = uri_list = g_uri_list_extract_uris( uri_list_str );
        while ( *puri )
        {
            file_path = g_filename_from_uri( *puri, NULL, NULL );
            if ( file_path )
            {
                files = g_list_prepend( files, file_path );
            }
            ++puri;
        }
        g_strfreev( uri_list );
        gtk_selection_data_free( sel_data );

        //sfm
        if ( files )
            files = g_list_reverse( files );

        /*
        * If only one item is selected and the item is a
        * directory, paste the files in that directory;
        * otherwise, paste the file in current directory.
        */

        task = ptk_file_task_new( action,
                                  files,
                                  dest_dir,
                                  GTK_WINDOW( parent_win ),
                                  GTK_WIDGET( task_view ) );
        ptk_file_task_run( task );
    }
}
Exemplo n.º 16
0
static void
drag_data_received_callback (GtkWidget *widget,
		       	     GdkDragContext *context,
		       	     int x,
		       	     int y,
		       	     GtkSelectionData *data,
		             guint info,
		             guint32 time,
			     gpointer callback_data)
{
	char **names;
	NemoApplication *application;
	int name_count;
	NemoWindow *new_window, *window;
	GdkScreen      *screen;
	gboolean new_windows_for_extras;
	char *prompt;
	char *detail;
	GFile *location;
	NemoLocationBar *self = NEMO_LOCATION_BAR (widget);

	g_assert (data != NULL);
	g_assert (callback_data == NULL);

	names = g_uri_list_extract_uris ((const gchar *) gtk_selection_data_get_data (data));

	if (names == NULL || *names == NULL) {
		g_warning ("No D&D URI's");
		g_strfreev (names);
		gtk_drag_finish (context, FALSE, FALSE, time);
		return;
	}

	window = nemo_location_bar_get_window (widget);
	new_windows_for_extras = FALSE;
	/* Ask user if they really want to open multiple windows
	 * for multiple dropped URIs. This is likely to have been
	 * a mistake.
	 */
	name_count = g_strv_length (names);
	if (name_count > 1) {
		prompt = g_strdup_printf (ngettext("Do you want to view %d location?",
						   "Do you want to view %d locations?",
						   name_count),
					  name_count);
		detail = g_strdup_printf (ngettext("This will open %d separate window.",
						   "This will open %d separate windows.",
						   name_count),
					  name_count);
		/* eel_run_simple_dialog should really take in pairs
		 * like gtk_dialog_new_with_buttons() does. */
		new_windows_for_extras = eel_run_simple_dialog
			(GTK_WIDGET (window),
			 TRUE,
			 GTK_MESSAGE_QUESTION,
			 prompt,
			 detail,
			 GTK_STOCK_CANCEL, GTK_STOCK_OK,
			 NULL) != 0 /* GNOME_OK */;

		g_free (prompt);
		g_free (detail);

		if (!new_windows_for_extras) {
			g_strfreev (names);
			gtk_drag_finish (context, FALSE, FALSE, time);
			return;
		}
	}

	nemo_location_bar_set_location (self, names[0]);
	emit_location_changed (self);

	if (new_windows_for_extras) {
		int i;

		application = nemo_application_get_singleton ();
		screen = gtk_window_get_screen (GTK_WINDOW (window));

		for (i = 1; names[i] != NULL; ++i) {
			new_window = nemo_application_create_window (application, screen);
			location = g_file_new_for_uri (names[i]);
			nemo_window_go_to (new_window, location);
			g_object_unref (location);
		}
	}

	g_strfreev (names);

	gtk_drag_finish (context, TRUE, FALSE, time);
}
Exemplo n.º 17
0
static void rc_gui_list2_dnd_data_received(GtkWidget *widget,
    GdkDragContext *context, gint x, gint y, GtkSelectionData *seldata,
    guint info, guint time, gpointer data)
{
    guint length = 0;
    gint i, j, k;
    gint *reorder_array = NULL;
    gint *indices = NULL;
    gint *index = NULL;
    gint target = 0;
    guint insert_num = 0;
    GList *path_list_foreach = NULL;
    GtkTreeViewDropPosition pos;
    GtkTreePath *path_start = NULL;
    GtkTreePath *path_drop = NULL;
    gint list_length = 0;
    gboolean insert_flag = FALSE;
    GList *path_list = NULL;
    gchar *uris = NULL;
    gchar **uri_array = NULL;
    gchar *uri = NULL;
    guint count = 0;
    gboolean flag = FALSE;
    gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(
        rc_ui->list2_tree_view), x,y, &path_drop, &pos);
    if(path_drop!=NULL)
    {
        index = gtk_tree_path_get_indices(path_drop);
        target = index[0];
        gtk_tree_path_free(path_drop);
    }
    else target = -2;
    switch(info)
    {
        case 1: 
        {
            memcpy(&path_list, gtk_selection_data_get_data(seldata),
                sizeof(path_list));
            if(path_list==NULL) break;
            length = g_list_length(path_list);
            indices = g_new(gint, length);
            for(path_list_foreach=path_list;path_list_foreach!=NULL;
                path_list_foreach=g_list_next(path_list_foreach))
            {
                path_start = path_list_foreach->data;
                index = gtk_tree_path_get_indices(path_start);
                indices[count] = index[0];
                count++;
            }
            g_qsort_with_data(indices, length, sizeof(gint),
                (GCompareDataFunc)rc_gui_list2_comp_func, NULL);
            if(pos==GTK_TREE_VIEW_DROP_AFTER ||
                pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER) target++;
            list_length = gtk_tree_model_iter_n_children(
                rc_ui->list2_tree_model, NULL);
            if(target<0) target = list_length;
            reorder_array = g_new0(gint, list_length);
            i = 0;
            j = 0;
            count = 0;
            while(i<list_length)
            {
                if((j>=length || count!=indices[j]) && count!=target)
                {
                    reorder_array[i] = count;
                    count++;
                    i++;
                }
                else if(count==target && !insert_flag)
                {
                    for(k=0;k<length;k++)
                    {
                        if(target==indices[k])
                        {
                            target++;
                            count++;
                        }
                        reorder_array[i] = indices[k];
                        i++;
                    }
                    reorder_array[i] = target;
                    i++;
                    count++;
                    insert_flag = TRUE;
                }
                else if(j<length && count==indices[j])
                {
                    count++;             
                    j++;
                }
                else break;
            }
            gtk_list_store_reorder(GTK_LIST_STORE(rc_ui->list2_tree_model),
                reorder_array);
            g_free(reorder_array);
            g_free(indices);
            break;
        }
        case 6:
        {
            uris = (gchar *)gtk_selection_data_get_data(seldata);
            if(uris==NULL) break;
            if(pos==GTK_TREE_VIEW_DROP_AFTER ||
                pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER) target++;
            list_length = gtk_tree_model_iter_n_children(
                rc_ui->list2_tree_model, NULL);
            if(target<0) target = list_length;
            uri_array = g_uri_list_extract_uris(uris);
            insert_num = 0;
            for(count=0;uri_array[count]!=NULL;count++)
            {
                uri = uri_array[count];
                if(rc_player_check_supported_format(uri))
                {
                    flag = rc_plist_insert_music(uri, 
                        rc_gui_list1_get_selected_index(), target);
                    target++;
                    insert_num++;
                }
            }
            g_strfreev(uri_array);
            if(insert_num>0)
                rc_gui_status_task_set(1, insert_num);
            break;
        }
        case 7:
        {
            rc_debug_module_perror(module_name,
                "Unknown dnd data in list2: %s",
                gtk_selection_data_get_data(seldata));
        }
        default: break;
    }
}
Exemplo n.º 18
0
static void
trash_applet_drag_data_received (GtkWidget        *widget,
                                 GdkDragContext   *context,
                                 gint              x,
                                 gint              y,
                                 GtkSelectionData *selectiondata,
                                 guint             info,
                                 guint             time_)
{
  gchar **list;
  gint i;
  GList *trashed = NULL;
  GList *untrashable = NULL;
  GList *l;
  GError *error = NULL;

  list = g_uri_list_extract_uris ((gchar *)gtk_selection_data_get_data (selectiondata));

  for (i = 0; list[i]; i++)
    {
      GFile *file;

      file = g_file_new_for_uri (list[i]);

      if (!g_file_trash (file, NULL, NULL))
        {
          untrashable = g_list_prepend (untrashable, file);
        }
      else
        {
          trashed = g_list_prepend (trashed, file);
        }
    }

  if (untrashable)
    {
      if (confirm_delete_immediately (widget,
                                      g_list_length (untrashable),
                                      trashed == NULL))
        {
          for (l = untrashable; l; l = l->next)
            {
              if (!g_file_delete (l->data, NULL, &error))
                {
/*
* FIXME: uncomment me after branched (we're string frozen)
                  error_dialog (applet,
                                _("Unable to delete '%s': %s"),
                                g_file_get_uri (l->data),
                                error->message);
*/
                                g_clear_error (&error);
                }
            }
        }
    }

  g_list_foreach (untrashable, (GFunc)g_object_unref, NULL);
  g_list_free (untrashable);
  g_list_foreach (trashed, (GFunc)g_object_unref, NULL);
  g_list_free (trashed);

  g_strfreev (list);

  gtk_drag_finish (context, TRUE, FALSE, time_);
}
Exemplo n.º 19
0
void
on_extensions_view_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *selectiondata, guint info, guint time)
{
	GFile *file;
	GFileInfo *file_info;
	gchar *type_name = NULL;

	/* Check that we got data from source */
	if(selectiondata == NULL || gtk_selection_data_get_length(selectiondata) < 0)
		goto fail;

	/* Check that we got the format we can use */
	type_name = gdk_atom_name(gtk_selection_data_get_data_type(selectiondata));
	if(strcmp(type_name, "text/uri-list") != 0)
		goto fail;

	/* Do stuff with the data */
	char **extension_files = g_uri_list_extract_uris((char *)gtk_selection_data_get_data(selectiondata));
	int foo;
	/* Get a list of URIs to the dropped files */
	for(foo = 0; extension_files[foo] != NULL; foo++) {
		GError *err = NULL;
		file = g_file_new_for_uri(extension_files[foo]);
		file_info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &err);
		if(!file_info) {
			IO_ERROR_DIALOG(NULL, file, err, _("accessing a URI"));
			goto fail2;
		}

		/* Check whether a directory was dropped. if so, install contents */
		/* NOTE: not recursive (that would be kind of silly anyway) */
		if(g_file_info_get_file_type(file_info) == G_FILE_TYPE_DIRECTORY) {

			GFileEnumerator *dir = g_file_enumerate_children(file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, &err);
			if(!dir) {
				IO_ERROR_DIALOG(NULL, file, err, _("opening a directory"));
				goto fail3;
			}

			GFileInfo *entry_info;
			while((entry_info = g_file_enumerator_next_file(dir, NULL, &err)) != NULL) {
				if(g_file_info_get_file_type(entry_info) != G_FILE_TYPE_DIRECTORY) {
					GFile *extension_file = g_file_get_child(file, g_file_info_get_name(entry_info));
					i7_app_install_extension(i7_app_get(), extension_file);
					g_object_unref(extension_file);
				}
				g_object_unref(entry_info);
			}
			g_file_enumerator_close(dir, NULL, &err);
			g_object_unref(dir);

			if(err) {
				IO_ERROR_DIALOG(NULL, file, err, _("reading a directory"));
				goto fail3;
			}

		} else {
			/* just install it */
			i7_app_install_extension(i7_app_get(), file);
		}

		g_object_unref(file_info);
		g_object_unref(file);
	}

	g_strfreev(extension_files);
	g_free(type_name);
	gtk_drag_finish(drag_context, TRUE, FALSE, time);
	return;

fail3:
	g_object_unref(file_info);
fail2:
	g_object_unref(file);
	g_strfreev(extension_files);
fail:
	g_free(type_name);
	gtk_drag_finish(drag_context, FALSE, FALSE, time);
}
Exemplo n.º 20
0
static void
drag_data_received_callback (GtkWidget *widget,
			     GdkDragContext *context,
			     int x,
			     int y,
			     GtkSelectionData *data,
			     guint info,
			     guint32 time,
			     gpointer callback_data)
{
	char **names;
	int name_count;
	GtkWidget *window;
	gboolean new_windows_for_extras;
	char *prompt;
	char *detail;
	GFile *location;
	NautilusLocationEntry *self = NAUTILUS_LOCATION_ENTRY (widget);

	g_assert (data != NULL);
	g_assert (callback_data == NULL);

	names = g_uri_list_extract_uris ((const gchar *) gtk_selection_data_get_data (data));

	if (names == NULL || *names == NULL) {
		g_warning ("No D&D URI's");
		gtk_drag_finish (context, FALSE, FALSE, time);
		return;
	}

	window = gtk_widget_get_toplevel (widget);
	new_windows_for_extras = FALSE;
	/* Ask user if they really want to open multiple windows
	 * for multiple dropped URIs. This is likely to have been
	 * a mistake.
	 */
	name_count = g_strv_length (names);
	if (name_count > 1) {
		prompt = g_strdup_printf (ngettext("Do you want to view %d location?",
						   "Do you want to view %d locations?",
						   name_count),
					  name_count);
		detail = g_strdup_printf (ngettext("This will open %d separate window.",
						   "This will open %d separate windows.",
						   name_count),
					  name_count);
		/* eel_run_simple_dialog should really take in pairs
		 * like gtk_dialog_new_with_buttons() does. */
		new_windows_for_extras = eel_run_simple_dialog (GTK_WIDGET (window),
								TRUE,
								GTK_MESSAGE_QUESTION,
								prompt,
								detail,
								_("_Cancel"), _("_OK"),
								NULL) != 0 /* GNOME_OK */;

		g_free (prompt);
		g_free (detail);

		if (!new_windows_for_extras) {
			gtk_drag_finish (context, FALSE, FALSE, time);
			return;
		}
	}

	location = g_file_new_for_uri (names[0]);
	nautilus_location_entry_set_location (self, location);
	emit_location_changed (self);
	g_object_unref (location);

	if (new_windows_for_extras) {
		int i;

		for (i = 1; names[i] != NULL; ++i) {
			location = g_file_new_for_uri (names[i]);
                        nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
                                                                 location, NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW, NULL, NULL, NULL);
			g_object_unref (location);
		}
	}

	g_strfreev (names);

	gtk_drag_finish (context, TRUE, FALSE, time);
}
Exemplo n.º 21
0
void ptk_clipboard_paste_targets( GtkWindow* parent_win,
                                const char* dest_dir,
                                GtkTreeView* task_view )   //MOD added
{
    GtkClipboard * clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD );
    GdkAtom gnome_target;
    GdkAtom uri_list_target;
    gchar **uri_list, **puri;
    GtkSelectionData* sel_data = NULL;
    GList* files = NULL;
    gchar* file_path;
    gint missing_targets = 0;
    char* str;
    
    PtkFileTask* task;
    VFSFileTaskType action;
    char* uri_list_str;

    gnome_target = gdk_atom_intern( "x-special/gnome-copied-files", FALSE );
    sel_data = gtk_clipboard_wait_for_contents( clip, gnome_target );
    if ( sel_data )
    {
        if ( sel_data->length <= 0 || sel_data->format != 8 )
            return ;

        uri_list_str = ( char* ) sel_data->data;
        action = VFS_FILE_TASK_COPY;
        if ( uri_list_str )
        {
            while ( *uri_list_str && *uri_list_str != '\n' )
                ++uri_list_str;
        }
    }
    else
    {
        uri_list_target = gdk_atom_intern( "text/uri-list", FALSE );
        sel_data = gtk_clipboard_wait_for_contents( clip, uri_list_target );
        if ( ! sel_data )
            return ;
        if ( sel_data->length <= 0 || sel_data->format != 8 )
            return ;
        uri_list_str = ( char* ) sel_data->data;
        action = VFS_FILE_TASK_COPY;
    }

    if ( uri_list_str )
    {
        puri = uri_list = g_uri_list_extract_uris( uri_list_str );
        while ( *puri )
        {
            file_path = g_filename_from_uri( *puri, NULL, NULL );
            if ( file_path )
            {
                if ( g_file_test( file_path, G_FILE_TEST_IS_SYMLINK ) )
                {
                    str = file_path;
                    file_path = g_file_read_link ( file_path, NULL );
                    g_free( str );
                }
                if ( file_path )
                {
                    if ( g_file_test( file_path, G_FILE_TEST_EXISTS ) )             
                        files = g_list_prepend( files, file_path );
                    else
                        missing_targets++;
                }
            }
            ++puri;
        }
        g_strfreev( uri_list );
        gtk_selection_data_free( sel_data );

        //sfm
        if ( files )
            files = g_list_reverse( files );

        task = ptk_file_task_new( action,
                                  files,
                                  dest_dir,
                                  GTK_WINDOW( parent_win ),
                                  GTK_WIDGET( task_view ) );
        ptk_file_task_run( task );
        
        if ( missing_targets > 0 )
            ptk_show_error( GTK_WINDOW( parent_win ),
                            g_strdup_printf ( "Error" ),
                            g_strdup_printf ( "%i target%s missing",
                            missing_targets, 
                            missing_targets > 1 ? g_strdup_printf ( "s are" ) : 
                            g_strdup_printf ( " is" ) ) );
    }
}
static void
caja_emblem_sidebar_drag_received_cb (GtkWidget *widget,
                                      GdkDragContext *drag_context,
                                      gint x,
                                      gint y,
                                      GtkSelectionData *data,
                                      guint info,
                                      guint time,
                                      CajaEmblemSidebar *emblem_sidebar)
{
    GSList *emblems;
    Emblem *emblem;
    GdkPixbuf *pixbuf;
    char *uri, *error, *uri_utf8;
    char **uris;
    GFile *f;
    int i;
    gboolean had_failure;
    gint data_format, data_length;
    const guchar *data_data;

    had_failure = FALSE;
    emblems = NULL;
    data_format = gtk_selection_data_get_format (data);
    data_length = gtk_selection_data_get_length (data);
    data_data = gtk_selection_data_get_data (data);

    switch (info)
    {
    case TARGET_URI_LIST:
        if (data_format != 8 ||
                data_length == 0)
        {
            g_message ("URI list had wrong format (%d) or length (%d)\n",
                       data_format, data_length);
            return;
        }

        uris = g_uri_list_extract_uris (data_data);
        if (uris == NULL)
        {
            break;
        }

        for (i = 0; uris[i] != NULL; ++i)
        {
            f = g_file_new_for_uri (uris[i]);
            pixbuf = caja_emblem_load_pixbuf_for_emblem (f);

            if (pixbuf == NULL)
            {
                /* this one apparently isn't an image, or
                 * at least not one that we know how to read
                 */
                had_failure = TRUE;
                g_object_unref (f);
                continue;
            }

            emblem = g_new (Emblem, 1);
            emblem->uri = g_file_get_uri (f);
            emblem->name = NULL; /* created later on by the user */
            emblem->keyword = NULL;
            emblem->pixbuf = pixbuf;

            g_object_unref (f);

            emblems = g_slist_prepend (emblems, emblem);
        }

        g_strfreev (uris);

        if (had_failure && emblems != NULL)
        {
            eel_show_error_dialog (_("Some of the files could not be added as emblems."), _("The emblems do not appear to be valid images."), NULL);
        }
        else if (had_failure && emblems == NULL)
        {
            eel_show_error_dialog (_("None of the files could be added as emblems."), _("The emblems do not appear to be valid images."), NULL);

        }

        if (emblems != NULL)
        {
            show_add_emblems_dialog (emblem_sidebar, emblems);
        }

        break;

    case TARGET_URI:
        if (data_format != 8 ||
                data_length == 0)
        {
            g_warning ("URI had wrong format (%d) or length (%d)\n",
                       data_format, data_length);
            return;
        }

        uri = g_strndup (data_data, data_length);

        f = g_file_new_for_uri (uri);
        pixbuf = caja_emblem_load_pixbuf_for_emblem (f);

        if (pixbuf != NULL)
        {
            emblem = g_new (Emblem, 1);
            emblem->uri = uri;
            emblem->name = NULL;
            emblem->keyword = NULL;
            emblem->pixbuf = pixbuf;

            emblems = g_slist_prepend (NULL, emblem);

            show_add_emblems_dialog (emblem_sidebar, emblems);
        }
        else
        {
            uri_utf8 = g_file_get_parse_name (f);

            if (uri_utf8)
            {
                error = g_strdup_printf (_("The file '%s' does not appear to be a valid image."), uri_utf8);
                g_free (uri_utf8);
            }
            else
            {
                error = g_strdup (_("The dragged file does not appear to be a valid image."));
            }
            eel_show_error_dialog (_("The emblem cannot be added."), error, NULL);
            g_free (error);
            g_free (uri_utf8);
        }

        g_object_unref (f);
        g_free (uri);

        break;

    case TARGET_NETSCAPE_URL:
        if (data_format != 8 ||
                data_length == 0)
        {
            g_message ("URI had wrong format (%d) or length (%d)\n",
                       data_format, data_length);
            return;
        }

        /* apparently, this is a URI/title pair?  or just a pair
         * of identical URIs?  Regardless, this seems to work...
         */

        uris = g_uri_list_extract_uris (data_data);
        if (uris == NULL)
        {
            break;
        }

        uri = uris[0];
        if (uri == NULL)
        {
            g_strfreev (uris);
            break;
        }

        f = g_file_new_for_uri (uri);
        pixbuf = caja_emblem_load_pixbuf_for_emblem (f);
        g_object_unref (f);

        if (pixbuf != NULL)
        {
            emblem = g_new (Emblem, 1);
            emblem->uri = g_strdup (uri);
            emblem->name = NULL;
            emblem->keyword = NULL;
            emblem->pixbuf = pixbuf;

            emblems = g_slist_prepend (NULL, emblem);

            show_add_emblems_dialog (emblem_sidebar, emblems);
        }
        else
        {
            g_warning ("Tried to load '%s', but failed.\n",
                       uri);
            error = g_strdup_printf (_("The file '%s' does not appear to be a valid image."), uri);
            eel_show_error_dialog (_("The emblem cannot be added."), error, NULL);
            g_free (error);
        }

        g_strfreev (uris);

        break;
    }
}
Exemplo n.º 23
0
static gboolean
drop_urilist (PanelWidget *panel,
	      int          pos,
	      char        *urilist)
{
	char     **uris;
	gboolean   success;
	int        i;

	uris = g_uri_list_extract_uris (urilist);

	success = TRUE;
	for (i = 0; uris[i]; i++) {
		GFile      *file;
		GFileInfo  *info;
		const char *uri;

		uri = uris[i];

		if (g_ascii_strncasecmp (uri, "http:", strlen ("http:")) == 0 ||
		    g_ascii_strncasecmp (uri, "https:", strlen ("https:")) == 0 ||
		    g_ascii_strncasecmp (uri, "ftp:", strlen ("ftp:")) == 0 ||
		    g_ascii_strncasecmp (uri, "gopher:", strlen ("gopher:")) == 0 ||
		    g_ascii_strncasecmp (uri, "ghelp:", strlen ("ghelp:")) == 0 ||
		    g_ascii_strncasecmp (uri, "man:", strlen ("man:")) == 0 ||
		    g_ascii_strncasecmp (uri, "info:", strlen ("info:")) == 0) {
			/* FIXME: probably do this only on link,
			 * in fact, on link always set up a link,
			 * on copy do all the other stuff.  Or something. */
			if ( ! drop_url (panel, pos, uri))
				success = FALSE;
			continue;
		}

		if (g_ascii_strncasecmp (uri, "x-caja-desktop:",
					 strlen ("x-caja-desktop:")) == 0) {
			success = drop_caja_desktop_uri (panel, pos, uri);
			continue;
		}

		file = g_file_new_for_uri (uri);
		info = g_file_query_info (file,
					  "standard::type,"
					  "standard::content-type,"
					  "access::can-execute",
					  G_FILE_QUERY_INFO_NONE,
					  NULL, NULL);

		if (info) {
			const char *mime;
			GFileType   type;
			gboolean    can_exec;

			mime = g_file_info_get_content_type (info);
			type = g_file_info_get_file_type (info);
			can_exec = g_file_info_get_attribute_boolean (info,
								      G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);

			if (mime &&
			    g_str_has_prefix (mime, "image")) {
				if (!set_background_image_from_uri (panel->toplevel, uri))
					success = FALSE;
			} else if (mime &&
				   (!strcmp (mime, "application/x-mate-app-info") ||
				    !strcmp (mime, "application/x-desktop") ||
				    !strcmp (mime, "application/x-kde-app-info"))) {
				if (panel_profile_id_lists_are_writable ())
					panel_launcher_create (panel->toplevel, pos, uri);
				else
					success = FALSE;
			} else if (type != G_FILE_TYPE_DIRECTORY && can_exec) {
				char *filename;

				filename = g_file_get_path (file);

				if (panel_profile_id_lists_are_writable ())
					/* executable and local, so add a
					 * launcher with it */
					ask_about_launcher (filename, panel,
							    pos, TRUE);
				else
					success = FALSE;
				g_free (filename);
			} else {
				if (!drop_uri (panel, pos, uri,
					       PANEL_ICON_UNKNOWN))
					success = FALSE;
			}
		} else {
			if (!drop_uri (panel, pos, uri, PANEL_ICON_UNKNOWN))
				success = FALSE;
		}

		g_object_unref (info);
		g_object_unref (file);
	}

	g_strfreev (uris);

	return success;
}
Exemplo n.º 24
0
gboolean fm_clipboard_paste_files(GtkWidget* dest_widget, FmPath* dest_dir)
{
	GdkDisplay* dpy = dest_widget ? gtk_widget_get_display(dest_widget) : gdk_display_get_default();
	GtkClipboard* clip = gtk_clipboard_get_for_display(dpy, GDK_SELECTION_CLIPBOARD);
	FmPathList* files;
	char** uris, **uri;
    GdkAtom atom;
    int type = 0;
    GdkAtom *avail_targets;
    int n, i;

    /* get all available targets currently in the clipboard. */
    if( !gtk_clipboard_wait_for_targets(clip, &avail_targets, &n) )
        return FALSE;

    /* check gnome and xfce compatible format first */
    atom = gdk_atom_intern_static_string(targets[GNOME_COPIED_FILES-1].target);
    for(i = 0; i < n; ++i)
    {
        if(avail_targets[i] == atom)
        {
            type = GNOME_COPIED_FILES;
            break;
        }
    }
    if( 0 == type ) /* x-special/gnome-copied-files is not found. */
    {
        /* check uri-list */
        atom = gdk_atom_intern_static_string(targets[URI_LIST-1].target);
        for(i = 0; i < n; ++i)
        {
            if(avail_targets[i] == atom)
            {
                type = URI_LIST;
                break;
            }
        }
        if( 0 == type ) /* text/uri-list is not found. */
        {
            /* finally, fallback to UTF-8 string */
            atom = gdk_atom_intern_static_string(targets[UTF8_STRING-1].target);
            for(i = 0; i < n; ++i)
            {
                if(avail_targets[i] == atom)
                {
                    type = UTF8_STRING;
                    break;
                }
            }
        }
    }
    g_free(avail_targets);

    if( type )
    {
        GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, atom);
        char* pdata = (char*)data->data;
        /* FIXME: is it safe to assume the clipboard data is null-terminalted?
         * According to the source code in gtkselection.c, gtk+ seems to 
         * includes an extra byte at the end of GtkSelectionData::data, so
         * this should be safe. */
        pdata[data->length] = '\0'; /* make sure the data is null-terminated. */
        is_cut = FALSE;

        switch(type)
        {
        case GNOME_COPIED_FILES:
            is_cut = g_str_has_prefix(pdata, "cut\n");
            while(*pdata && *pdata != '\n')
                ++pdata;
            ++pdata;
            /* the following parts is actually a uri-list, so don't break here. */
        case URI_LIST:
            uris = g_uri_list_extract_uris(pdata);
            if( type != GNOME_COPIED_FILES )
            {
                /* if we're not handling x-special/gnome-copied-files, check 
                 * if information from KDE is available. */
                is_cut = check_kde_curselection(clip);
            }
            break;
        case UTF8_STRING:
            /* FIXME: how should we treat UTF-8 strings? URIs or filenames? */
            uris = g_uri_list_extract_uris(pdata);
            break;
        }
        gtk_selection_data_free(data);

        if(uris)
        {
        	files = fm_path_list_new_from_uris((const char **)uris);
            g_strfreev(uris);

            if( is_cut )
                fm_move_files(files, dest_dir);
            else
                fm_copy_files(files, dest_dir);
            fm_list_unref(files);

            return TRUE;
        }
    }
    return FALSE;
}