Example #1
0
void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard)
{
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    if (gtk_clipboard_wait_is_text_available(clipboard)) {
        GOwnPtr<gchar> textData(gtk_clipboard_wait_for_text(clipboard));
        if (textData)
            dataObject->setText(String::fromUTF8(textData.get()));
    }

    if (gtk_clipboard_wait_is_target_available(clipboard, markupAtom)) {
        if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, markupAtom)) {
            String markup(selectionDataToUTF8String(data));
            removeMarkupPrefix(markup);
            dataObject->setMarkup(markup);
            gtk_selection_data_free(data);
        }
    }

    if (gtk_clipboard_wait_is_target_available(clipboard, uriListAtom)) {
        if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, uriListAtom)) {
            dataObject->setURIList(selectionDataToUTF8String(data));
            gtk_selection_data_free(data);
        }
    }
}
void
nautilus_clipboard_clear_if_colliding_uris (GtkWidget *widget,
					    const GList *item_uris,
					    GdkAtom copied_files_atom)
{
	GtkSelectionData *data;
	GList *clipboard_item_uris, *l;
	gboolean collision;

	collision = FALSE;
	data = gtk_clipboard_wait_for_contents (nautilus_clipboard_get (widget),
						copied_files_atom);
	if (data == NULL) {
		return;
	}

	clipboard_item_uris = nautilus_clipboard_get_uri_list_from_selection_data (data, NULL,
										   copied_files_atom);

	for (l = (GList *) item_uris; l; l = l->next) {
		if (g_list_find_custom ((GList *) item_uris, l->data,
					(GCompareFunc) g_strcmp0)) {
			collision = TRUE;
			break;
		}
	}
	
	if (collision) {
		gtk_clipboard_clear (nautilus_clipboard_get (widget));
	}
	
	if (clipboard_item_uris) {
		g_list_free_full (clipboard_item_uris, g_free);
	}
}
Example #3
0
static void load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
{
    CopyAndPasteFixture* fixture = (CopyAndPasteFixture*)data;
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status != WEBKIT_LOAD_FINISHED)
        return;

    GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
    gtk_clipboard_clear(clipboard);

    webkit_web_view_copy_clipboard(webView);

    gchar* text = gtk_clipboard_wait_for_text(clipboard);
    g_assert(text || !fixture->info->expectedContent);
    g_assert(!text || !strcmp(text, fixture->info->expectedContent));
    g_free(text);

    // Verify that the markup starts with the proper content-type meta tag prefix.
    GtkSelectionData* selectionData = gtk_clipboard_wait_for_contents(clipboard, gdk_atom_intern("text/html", FALSE));
    if (selectionData) {
        static const char* markupPrefix = "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">";
        char* markup = g_strndup((const char*) gtk_selection_data_get_data(selectionData),
            gtk_selection_data_get_length(selectionData));
        g_assert(strlen(markupPrefix) <= strlen(markup));
        g_assert(!strncmp(markupPrefix, markup, strlen(markupPrefix)));
        g_free(markup);
    }

    g_assert(!gtk_clipboard_wait_is_uris_available(clipboard));
    g_assert(!gtk_clipboard_wait_is_image_available(clipboard));

    g_main_loop_quit(fixture->loop);
}
Example #4
0
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context,
                                                          bool allowPlainText, bool& chosePlainText)
{
    GdkAtom textHtml = gdk_atom_intern_static_string("text/html");
    GtkClipboard* clipboard = m_helper->getCurrentTarget(frame);
    chosePlainText = false;

    if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, textHtml)) {
        ASSERT(data->data);
        String html = String::fromUTF8(reinterpret_cast<gchar*>(data->data), data->length * data->format / 8);
        gtk_selection_data_free(data);

        if (!html.isEmpty()) {
            RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "");
            if (fragment)
                return fragment.release();
        }
    }

    if (!allowPlainText)
        return 0;

    if (gchar* utf8 = gtk_clipboard_wait_for_text(clipboard)) {
        String text = String::fromUTF8(utf8);
        g_free(utf8);

        chosePlainText = true;
        RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), text);
        if (fragment)
            return fragment.release();
    }

    return 0;
}
Example #5
0
/* \brief Get the contents of the system clipboard.
 * \par Function Description
 * If the system clipboard contains schematic data, retrieve it.
 *
 * \param [in,out] w_current   The current GSCHEM_TOPLEVEL.
 *
 * \returns Any OBJECTs retrieved from the system clipboard, or NULL
 *          if none were available.
 */
GList *
x_clipboard_get (GSCHEM_TOPLEVEL *w_current)
{
  GtkClipboard *cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
  TOPLEVEL *toplevel = w_current->toplevel;
  GdkAtom type = gdk_atom_intern (MIME_TYPE_SCHEMATIC, FALSE);
  GtkSelectionData *selection_data;
  GList *object_list = NULL;
  const guchar *buf;

  /* Try to get the contents of the clipboard */
  selection_data = gtk_clipboard_wait_for_contents (cb, type);
  if (selection_data == NULL) return FALSE;

  /* Convert the data buffer to OBJECTs */
#if GTK_CHECK_VERSION(2,14,0)
  buf = gtk_selection_data_get_data (selection_data);
#else
  buf = selection_data->data;
#endif

  object_list = o_read_buffer (toplevel, object_list,
                               (gchar *) buf, -1, "Clipboard");

  gtk_selection_data_free (selection_data);
  return object_list;
}
Example #6
0
static VALUE
rg_wait_for_contents(VALUE self, VALUE target)
{
    return BOXED2RVAL(gtk_clipboard_wait_for_contents(
                          _SELF(self), 
                          RVAL2ATOM(target)), 
                      GTK_TYPE_SELECTION_DATA);
}
Example #7
0
/**
 * gimp_clipboard_get_svg:
 * @gimp: pointer to #Gimp
 * @svg_length: returns the size of the SVG stream in bytes
 *
 * Retrieves SVG data from %GDK_SELECTION_CLIPBOARD or from the global
 * SVG buffer of @gimp.
 *
 * The returned data needs to be freed when it's no longer needed.
 *
 * Return value: a reference to a #GimpBuffer or %NULL if there's no
 *               image data
 **/
gchar *
gimp_clipboard_get_svg (Gimp  *gimp,
                        gsize *svg_length)
{
  GimpClipboard *gimp_clip;
  GtkClipboard  *clipboard;
  GdkAtom        atom;
  gchar         *svg = NULL;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (svg_length != NULL, NULL);

  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
                                             GDK_SELECTION_CLIPBOARD);

  if (clipboard                                                      &&
      gtk_clipboard_get_owner (clipboard)         != G_OBJECT (gimp) &&
      (atom = gimp_clipboard_wait_for_svg (gimp)) != GDK_NONE)
    {
      GtkSelectionData *data;

      gimp_set_busy (gimp);

      data = gtk_clipboard_wait_for_contents (clipboard, atom);

      if (data)
        {
          const guchar *stream;

          stream = gimp_selection_data_get_stream (data, svg_length);

          if (stream)
            svg = g_memdup (stream, *svg_length);

          gtk_selection_data_free (data);
        }

      gimp_unset_busy (gimp);
    }

  gimp_clip = gimp_clipboard_get (gimp);

  if (! svg && gimp_clip->svg)
    {
      svg = g_strdup (gimp_clip->svg);
      *svg_length = strlen (svg);
    }

  return svg;
}
Example #8
0
gboolean check_kde_curselection(GtkClipboard* clip)
{
    /* Check application/x-kde-cutselection:
     * If the content of this format is string "1", that means the
     * file is cut in KDE (Dolphin). */
    gboolean ret = FALSE;
    GdkAtom atom = gdk_atom_intern_static_string(targets[KDE_CUT_SEL-1].target);
    GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, atom);
    if(data)
    {
        if(data->length > 0 && data->format == 8 && data->data[0] == '1')
            ret = TRUE;
        gtk_selection_data_free(data);
    }
    return ret;
}
Example #9
0
/*
 *	get data from clipboard ownered by others.
 */
static gboolean
__request_clipboard_contents (FileOpsClipboardInfo* info)
{
    g_debug ("__request_clipboard_contents: begin");
    //gtk_clipboard_request_contents (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
    //				    copied_files_atom,
    //				    __clipboard_contents_received_callback,
    //				    info);
    // Use synchronous version
    GtkSelectionData * selection_data;
    selection_data = gtk_clipboard_wait_for_contents (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
				                      copied_files_atom);
    __clipboard_contents_received_callback (NULL, selection_data, info);
    g_debug ("__request_clipboard_contents: end; num: %d", info->num);
    return info->num ? TRUE : FALSE;
}
Example #10
0
/**
 * gimp_clipboard_get_buffer:
 * @gimp: pointer to #Gimp
 *
 * Retrieves either image data from %GDK_SELECTION_CLIPBOARD or from
 * the global cut buffer of @gimp.
 *
 * The returned #GimpBuffer needs to be unref'ed when it's no longer
 * needed.
 *
 * Return value: a reference to a #GimpBuffer or %NULL if there's no
 *               image data
 **/
GimpBuffer *
gimp_clipboard_get_buffer (Gimp *gimp)
{
  GimpClipboard *gimp_clip;
  GtkClipboard  *clipboard;
  GdkAtom        atom;
  GimpBuffer    *buffer = NULL;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
                                             GDK_SELECTION_CLIPBOARD);

  if (clipboard                                                         &&
      gtk_clipboard_get_owner (clipboard)            != G_OBJECT (gimp) &&
      (atom = gimp_clipboard_wait_for_buffer (gimp)) != GDK_NONE)
    {
      GtkSelectionData *data;

      gimp_set_busy (gimp);

      data = gtk_clipboard_wait_for_contents (clipboard, atom);

      if (data)
        {
          GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);

          gtk_selection_data_free (data);

          if (pixbuf)
            {
              buffer = gimp_buffer_new_from_pixbuf (pixbuf, _("Clipboard"));
              g_object_unref (pixbuf);
            }
        }

      gimp_unset_busy (gimp);
    }

  gimp_clip = gimp_clipboard_get (gimp);

  if (! buffer && gimp_clip->buffer)
    buffer = g_object_ref (gimp_clip->buffer);

  return buffer;
}
Example #11
0
static GdkAtom *
gimp_clipboard_wait_for_targets (Gimp *gimp,
                                 gint *n_targets)
{
  GtkClipboard *clipboard;

  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
                                             GDK_SELECTION_CLIPBOARD);

  if (clipboard)
    {
      GtkSelectionData *data;
      GdkAtom           atom = gdk_atom_intern_static_string ("TARGETS");

      data = gtk_clipboard_wait_for_contents (clipboard, atom);

      if (data)
        {
          GdkAtom  *targets;
          gboolean  success;

          success = gtk_selection_data_get_targets (data, &targets, n_targets);

          gtk_selection_data_free (data);

          if (success)
            {
              if (gimp->be_verbose)
                {
                  gint i;

                  for (i = 0; i < *n_targets; i++)
                    g_printerr ("clipboard: offered type: %s\n",
                                gdk_atom_name (targets[i]));

                  g_printerr ("\n");
                }

              return targets;
            }
        }
    }

  return NULL;
}
Example #12
0
/* \brief Get the contents of the system clipboard.
 * \par Function Description
 * If the system clipboard contains schematic data, retrieve it.
 *
 * \param [in,out] w_current   The current GSCHEM_TOPLEVEL.
 *
 * \returns Any OBJECTs retrieved from the system clipboard, or NULL
 *          if none were available.
 */
GList *
x_clipboard_get (GSCHEM_TOPLEVEL *w_current)
{
  GtkClipboard *cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
  TOPLEVEL *toplevel = w_current->toplevel;
  GdkAtom type = gdk_atom_intern (MIME_TYPE_SCHEMATIC, FALSE);
  GtkSelectionData *selection_data;
  GList *object_list = NULL;
  const guchar *buf;
  GError * err = NULL;

  /* Try to get the contents of the clipboard */
  selection_data = gtk_clipboard_wait_for_contents (cb, type);
  if (selection_data == NULL) return FALSE;

  /* Convert the data buffer to OBJECTs */
#if GTK_CHECK_VERSION(2,14,0)
  buf = gtk_selection_data_get_data (selection_data);
#else
  buf = selection_data->data;
#endif

  object_list = o_read_buffer (toplevel, object_list,
                               (gchar *) buf, -1, "Clipboard", &err);

  if (err) {
    GtkWidget * dialog = gtk_message_dialog_new_with_markup
      (GTK_WINDOW (w_current->main_window),
       GTK_DIALOG_DESTROY_WITH_PARENT,
       GTK_MESSAGE_ERROR,
       GTK_BUTTONS_OK,
       _("<b>Invalid schematic on clipboard.</b>\n\nAn error occurred while inserting clipboard data: %s."),
       err->message);
    gtk_window_set_title (GTK_WINDOW (dialog), _("Clipboard insertion failed"));

     gtk_dialog_run (GTK_DIALOG (dialog));
     gtk_widget_destroy (dialog);
     g_error_free(err);
  }
  gtk_selection_data_free (selection_data);
  return object_list;
}
static jobject get_data_raw(JNIEnv *env, const char* mime, gboolean string_data)
{
    GtkSelectionData *data;
    const guchar *raw_data;
    jsize length;
    jbyteArray array;
    jobject result = NULL;
    data = gtk_clipboard_wait_for_contents(get_clipboard(), gdk_atom_intern(mime, FALSE));
    if (data != NULL) {
        raw_data = glass_gtk_selection_data_get_data_with_length(data, &length);
        if (string_data) {
            result = env->NewStringUTF((const char*)raw_data);
        } else {
            array = env->NewByteArray(length);
            env->SetByteArrayRegion(array, 0, length, (const jbyte*)raw_data);
            result = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, array);
        }
        gtk_selection_data_free(data);
    }
    return result;
}
Example #14
0
// work out what format the clipboard data is in, and paste accordingly
void clipboard_paste(void)
{
  GtkSelectionData *sel_data;
  GtkClipboard *clipboard;
  GdkPixbuf *pixbuf;
  gchar *text;

  if (ui.cur_layer == NULL) return;
  
  ui.cur_item_type = ITEM_PASTE;
  clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
  // try xournal data
  sel_data = gtk_clipboard_wait_for_contents(
      clipboard,
      gdk_atom_intern(XOURNAL_TARGET_ATOM, FALSE));
#ifdef WIN32 // avoid a win32 bug showing images as xournal data
  if (gtk_selection_data_get_data_type(sel_data)!=gdk_atom_intern(XOURNAL_TARGET_ATOM, FALSE))
    { gtk_selection_data_free(sel_data); sel_data = NULL; }
#endif
  ui.cur_item_type = ITEM_NONE;
  if (sel_data != NULL) { 
    clipboard_paste_from_xournal(sel_data);
    return;
  } 
  // try image data
  pixbuf = gtk_clipboard_wait_for_image(clipboard);
  if (pixbuf != NULL) {
    clipboard_paste_image(pixbuf);
    return;
  }
  // try text data
  text = gtk_clipboard_wait_for_text(clipboard);
  if (text != NULL) {
    clipboard_paste_text(text);
    return;
  }
}
Example #15
0
void
clipboard_paste_selection (ddb_playlist_t *plt, int ctx)
{
    if (!plt) {
        return;
    }
    GdkDisplay *display = mainwin ? gtk_widget_get_display (mainwin) : gdk_display_get_default();
    GtkClipboard *clip = gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD);
    int type = 0;
    GdkAtom *avail_targets = NULL;
    int n = 0;

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

    clipboard_check_atoms ();

    // we prefer DDB_URI_LIST, so first check all tragets for that
    for (int i = 0; i < n; i++) {
        if (avail_targets[i] == target_atom[DDB_URI_LIST]) {
            type = DDB_URI_LIST;
            break;
        }
    }
    if (type == 0) {
        // no DDB_URI_LIST, check for other supported targets
        for (int i = 0; i < n; i++) {
            if (avail_targets[i] == target_atom[GNOME_COPIED_FILES]) {
                type = GNOME_COPIED_FILES;
                break;
            }
            else if (avail_targets[i] == target_atom[URI_LIST]) {
                type = URI_LIST;
                break;
            }
        }
    }
    g_free (avail_targets);

    if (type) {
        GtkSelectionData *data = gtk_clipboard_wait_for_contents (clip, target_atom[type]);
        const gchar *pdata = (const gchar *)gtk_selection_data_get_data (data);
        gint data_len = gtk_selection_data_get_length (data);

        switch (type) {
            case DDB_URI_LIST:
                clipboard_activate_dest_playlist (pdata, plt, ctx);
                clipboard_received_ddb_uri_list (pdata);
                break;
            case GNOME_COPIED_FILES:
                clipboard_activate_dest_playlist (NULL, plt, ctx);
                clipboard_received_uri_list (pdata, data_len);
                break;
            case URI_LIST:
                clipboard_activate_dest_playlist (NULL, plt, ctx);
                clipboard_received_uri_list (pdata, data_len);
                break;
            default:
                break;
        }
        gtk_selection_data_free (data);
    }
}
Example #16
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" ) ) );
    }
}
Example #17
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 );
    }
}
Example #18
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 );
    }
}
Example #19
0
static gboolean
term_key_event (GtkWidget * widget, GdkEventKey * event, gpointer user_data)
{
	terms_t *terms = (terms_t *) user_data;
	bind_t	*cur;
	guint state = event->state;
	GtkClipboard *clipboard;
	gchar *text;

	state &= 0xED;
//	fprintf (stderr, "%s: keyval: %d, state: 0x%x\n", __func__, event->keyval, state);

	for (cur = terms->keys; cur; cur = cur->next) {
		if ((event->keyval >= cur->key_min) && (event->keyval <= cur->key_max)) {
			if (state == cur->state) {
				switch (cur->action) {
					case BIND_ACT_SWITCH:
						term_switch (terms, cur->base + (event->keyval - cur->key_min), cur->cmd);
						break;
					case BIND_ACT_CUT:
						widget = gtk_notebook_get_nth_page(terms->notebook, gtk_notebook_get_current_page(terms->notebook));
						if (GTK_WIDGET_REALIZED(widget)) {
							clipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(widget), GDK_SELECTION_CLIPBOARD);
						} else {
							clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* wing it */
						}

						text = temu_terminal_get_selection_text(widget);

//						printf("cut: '%s'\n", text);
						gtk_clipboard_set_text(clipboard, text, strlen(text));
						break;
					case BIND_ACT_PASTE:
						widget = gtk_notebook_get_nth_page(terms->notebook, gtk_notebook_get_current_page(terms->notebook));
						if (GTK_WIDGET_REALIZED(widget)) {
							clipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(widget), GDK_SELECTION_CLIPBOARD);
						} else {
							clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* wing it */
						}

						text = gtk_clipboard_wait_for_text(clipboard);
						if (text) {
							//printf("paste: '%s'\n", text);
							temu_terminal_insert_text(widget, text);
							g_free(text);
						} else { // Oh boy, this is going to be 'Fun'.
							GtkSelectionData *data;
							data = gtk_clipboard_wait_for_contents(clipboard, gdk_atom_intern_static_string("STRING"));
							if (data) {
								//printf("paste; len: %d, '%s'\n", data->length, data->data);
								{
									char buf[data->length + 1];
									memset(buf, '\0', data->length + 1);
									memcpy(buf, data->data, data->length);
									temu_terminal_insert_text(widget, buf);
								}
								gtk_selection_data_free(data);
							}
						}
						break;
				}
				return TRUE;
			}
		}
	}

	return FALSE;
}
Example #20
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;
}