Ejemplo n.º 1
0
static void on_open_in_new_win(GtkAction* act, FmMainWin* win)
{
    FmPathList* sels = fm_folder_view_dup_selected_file_paths(win->folder_view);
    GList* l;
    for( l = fm_path_list_peek_head_link(sels); l; l=l->next )
    {
        FmPath* path = (FmPath*)l->data;
        fm_main_win_add_win(win, path);
    }
    fm_path_list_unref(sels);
}
Ejemplo n.º 2
0
/**
 * fm_file_info_job_new
 * @files_to_query: (allow-none): list of paths to query informatiom
 * @flags: modificators of query mode
 *
 * Creates a new #FmFileInfoJob which can be used by #FmJob API.
 *
 * Returns: (transfer full): a new #FmFileInfoJob object.
 *
 * Since: 0.1.0
 */
FmFileInfoJob* fm_file_info_job_new(FmPathList* files_to_query, FmFileInfoJobFlags flags)
{
    GList* l;
    FmFileInfoJob* job = (FmFileInfoJob*)g_object_new(FM_TYPE_FILE_INFO_JOB, NULL);
    FmFileInfoList* file_infos;

    job->flags = flags;
    if(files_to_query)
    {
        file_infos = job->file_infos;
        for(l = fm_path_list_peek_head_link(files_to_query);l;l=l->next)
        {
            FmPath* path = FM_PATH(l->data);
            FmFileInfo* fi = fm_file_info_new();
            fm_file_info_set_path(fi, path);
            fm_file_info_list_push_tail_noref(file_infos, fi);
        }
    }
    return job;
}
Ejemplo n.º 3
0
/**
 * fm_trash_or_delete_files
 * @parent: a window to place progress dialog over it
 * @files: list of files to delete
 *
 * Removes files into trash can if that operation is supported.
 * Otherwise erases them. If that operation takes some time then progress
 * dialog will be opened.
 *
 * Before 0.1.15 this call had different arguments.
 *
 * Since: 0.1.0
 */
void fm_trash_or_delete_files(GtkWindow* parent, FmPathList* files)
{
    if( !fm_path_list_is_empty(files) )
    {
        gboolean all_in_trash = TRUE;
        if(fm_config->use_trash)
        {
            GList* l = fm_path_list_peek_head_link(files);
            for(;l;l=l->next)
            {
                FmPath* path = FM_PATH(l->data);
                if(!fm_path_is_trash(path))
                    all_in_trash = FALSE;
            }
        }

        /* files already in trash:/// should only be deleted and cannot be trashed again. */
        if(fm_config->use_trash && !all_in_trash)
            fm_trash_files(parent, files);
        else
            fm_delete_files(parent, files);
    }
}
Ejemplo n.º 4
0
static gboolean fm_deep_count_job_run(FmJob* job)
{
    FmDeepCountJob* dc = (FmDeepCountJob*)job;
    GList* l;

    l = fm_path_list_peek_head_link(dc->paths);
    for(; !fm_job_is_cancelled(job) && l; l=l->next)
    {
        FmPath* path = FM_PATH(l->data);
        if(fm_path_is_native(path)) /* if it's a native file, use posix APIs */
        {
            char *path_str = fm_path_to_str(path);
            deep_count_posix( dc, path_str );
            g_free(path_str);
        }
        else
        {
            GFile* gf = fm_path_to_gfile(path);
            deep_count_gio( dc, NULL, gf );
            g_object_unref(gf);
        }
    }
    return TRUE;
}
Ejemplo n.º 5
0
static gboolean on_show_dlg(gpointer user_data)
{
    FmProgressDisplay* data = (FmProgressDisplay*)user_data;
    GtkBuilder* builder;
    GtkLabel* to;
    GtkWidget *to_label;
    FmPath* dest;
    const char* title = NULL;
    GtkTextTagTable* tag_table;

    GDK_THREADS_ENTER();
    if(g_source_is_destroyed(g_main_current_source()))
        goto _end;

    builder = gtk_builder_new();
    tag_table = gtk_text_tag_table_new();
    gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
    gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/progress.ui", NULL);

    data->dlg = GTK_DIALOG(gtk_builder_get_object(builder, "dlg"));
    g_object_weak_ref(G_OBJECT(data->dlg), on_progress_dialog_destroy, data);

    g_signal_connect(data->dlg, "response", G_CALLBACK(on_response), data);
    /* FIXME: connect to "close" signal */

    to_label = (GtkWidget*)gtk_builder_get_object(builder, "to_label");
    to = GTK_LABEL(gtk_builder_get_object(builder, "dest"));
    data->icon = GTK_IMAGE(gtk_builder_get_object(builder, "icon"));
    data->msg = GTK_LABEL(gtk_builder_get_object(builder, "msg"));
    data->act = GTK_LABEL(gtk_builder_get_object(builder, "action"));
    data->src = GTK_LABEL(gtk_builder_get_object(builder, "src"));
    data->dest = (GtkWidget*)gtk_builder_get_object(builder, "dest");
    data->current = GTK_LABEL(gtk_builder_get_object(builder, "current"));
    data->progress = GTK_PROGRESS_BAR(gtk_builder_get_object(builder, "progress"));
    data->error_pane = (GtkWidget*)gtk_builder_get_object(builder, "error_pane");
    data->error_msg = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "error_msg"));
    data->remaining_time = GTK_LABEL(gtk_builder_get_object(builder, "remaining_time"));

    data->bold_tag = gtk_text_tag_new("bold");
    g_object_set(data->bold_tag, "weight", PANGO_WEIGHT_BOLD, NULL);
    gtk_text_tag_table_add(tag_table, data->bold_tag);
    data->error_buf = gtk_text_buffer_new(tag_table);
    g_object_unref(tag_table);
    gtk_text_view_set_buffer(data->error_msg, data->error_buf);

    g_object_unref(builder);

    /* set the src label */
    /* FIXME: direct access to job struct! */
    if(data->job->srcs)
    {
        GList* l = fm_path_list_peek_head_link(data->job->srcs);
        int i;
        char* disp;
        FmPath* path;
        GString* str = g_string_sized_new(512);
        path = FM_PATH(l->data);
        disp = fm_path_display_basename(path);
        g_string_assign(str, disp);
        g_free(disp);
        for( i =1, l=l->next; i < 10 && l; l=l->next, ++i)
        {
            path = FM_PATH(l->data);
            g_string_append(str, _(", "));
            disp = fm_path_display_basename(path);
            g_string_append(str, disp);
            g_free(disp);
        }
        if(l)
            g_string_append(str, "...");
        gtk_label_set_text(data->src, str->str);
        g_string_free(str, TRUE);
    }

    /* FIXME: use accessor functions instead */
    /* FIXME: direct access to job struct! */
    switch(data->job->type)
    {
    case FM_FILE_OP_MOVE:
        title = _("Moving files");
        break;
    case FM_FILE_OP_COPY:
        title = _("Copying files");
        break;
    case FM_FILE_OP_TRASH:
        title = _("Trashing files");
        break;
    case FM_FILE_OP_DELETE:
        title = _("Deleting files");
        break;
    case FM_FILE_OP_LINK:
        title = _("Creating symlinks");
        break;
    case FM_FILE_OP_CHANGE_ATTR:
        title = _("Changing file attributes");
        break;
    case FM_FILE_OP_UNTRASH:
        break;
    case FM_FILE_OP_NONE: ;
    }
    if(title)
    {
        gtk_window_set_title(GTK_WINDOW(data->dlg), title);
        gtk_label_set_text(data->act, title);
    }

    dest = fm_file_ops_job_get_dest(data->job);
    if(dest)
    {
        char* dest_str = fm_path_display_name(dest, TRUE);
        gtk_label_set_text(to, dest_str);
        g_free(dest_str);
    }
    else
    {
        gtk_widget_destroy(data->dest);
        gtk_widget_destroy(to_label);
    }

    gtk_window_set_transient_for(GTK_WINDOW(data->dlg), data->parent);
    gtk_window_present(GTK_WINDOW(data->dlg));
    data->update_timeout = g_timeout_add(500, on_update_dlg, data);

    data->delay_timeout = 0;
_end:
    GDK_THREADS_LEAVE();
    return FALSE;
}
Ejemplo n.º 6
0
gboolean _fm_file_ops_job_move_run(FmFileOpsJob* job)
{
    GFile *dest_dir;
    GFileInfo* inf;
    GList* l;
    GError* err = NULL;
    FmJob* fmjob = FM_JOB(job);
    dev_t dest_dev = 0;
    gboolean ret = TRUE;
    FmDeepCountJob* dc;
    FmPath *parent = NULL;
    FmFolder *df, *sf = NULL;

    /* get information of destination folder */
    g_return_val_if_fail(job->dest, FALSE);
    dest_dir = fm_path_to_gfile(job->dest);
_retry_query_dest_info:
    inf = g_file_query_info(dest_dir, G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL","
                                  G_FILE_ATTRIBUTE_UNIX_DEVICE","
                                  G_FILE_ATTRIBUTE_ID_FILESYSTEM","
                                  G_FILE_ATTRIBUTE_UNIX_DEVICE, 0,
                                  fm_job_get_cancellable(fmjob), &err);
    if(inf)
    {
        job->dest_fs_id = g_intern_string(g_file_info_get_attribute_string(inf, G_FILE_ATTRIBUTE_ID_FILESYSTEM));
        dest_dev = g_file_info_get_attribute_uint32(inf, G_FILE_ATTRIBUTE_UNIX_DEVICE); /* needed by deep count */
        g_object_unref(inf);
    }
    else
    {
        FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MODERATE);
        g_error_free(err);
        err = NULL;
        if(act == FM_JOB_RETRY)
            goto _retry_query_dest_info;
        else
        {
            g_object_unref(dest_dir);
            return FALSE;
        }
    }

    /* prepare the job, count total work needed with FmDeepCountJob */
    dc = fm_deep_count_job_new(job->srcs, FM_DC_JOB_PREPARE_MOVE);
    fm_deep_count_job_set_dest(dc, dest_dev, job->dest_fs_id);
    fm_job_run_sync(FM_JOB(dc));
    job->total = dc->total_size;

    if( fm_job_is_cancelled(FM_JOB(dc)) )
    {
        g_object_unref(dest_dir);
        g_object_unref(dc);
        return FALSE;
    }
    g_object_unref(dc);
    g_debug("total size to move: %llu, dest_fs: %s",
            (long long unsigned int)job->total, job->dest_fs_id);

    fm_file_ops_job_emit_prepared(job);
    /* suspend updates for destination */
    df = fm_folder_find_by_path(job->dest);
    if (df)
        fm_folder_block_updates(df);

    for(l = fm_path_list_peek_head_link(job->srcs); !fm_job_is_cancelled(fmjob) && l; l=l->next)
    {
        FmPath* path = FM_PATH(l->data);
        GFile* src = fm_path_to_gfile(path);
        GFile* dest;
        char* tmp_basename;

        /* do with updates for source */
        if (fm_path_get_parent(path) != parent && fm_path_get_parent(path) != NULL)
        {
            FmFolder *pf;

            pf = fm_folder_find_by_path(fm_path_get_parent(path));
            if (pf != sf)
            {
                if (sf)
                {
                    fm_folder_unblock_updates(sf);
                    g_object_unref(sf);
                }
                if (pf)
                    fm_folder_block_updates(pf);
                sf = pf;
            }
            else if (pf)
                g_object_unref(pf);
        }
        parent = fm_path_get_parent(path);
        if(g_file_is_native(src) && g_file_is_native(dest_dir))
            /* both are native */
            tmp_basename = NULL;
        else if(g_file_is_native(src)) /* move from native to virtual */
            tmp_basename = g_filename_to_utf8(fm_path_get_basename(path),
                                              -1, NULL, NULL, NULL);
            /* gvfs escapes it itself */
        else /* move from virtual to native/virtual */
            tmp_basename = fm_uri_subpath_to_native_subpath(fm_path_get_basename(path), NULL);
        dest = g_file_get_child(dest_dir,
                        tmp_basename ? tmp_basename : fm_path_get_basename(path));
        g_free(tmp_basename);

        if(!_fm_file_ops_job_move_file(job, src, NULL, dest, path, sf, df))
            ret = FALSE;
        g_object_unref(src);
        g_object_unref(dest);

        if(!ret)
            break;
    }
    /* restore updates for destination and source */
    if (df)
    {
        fm_folder_unblock_updates(df);
        g_object_unref(df);
    }
    if (sf)
    {
        fm_folder_unblock_updates(sf);
        g_object_unref(sf);
    }

    g_object_unref(dest_dir);
    return ret;
}
Ejemplo n.º 7
0
gboolean _fm_file_ops_job_copy_run(FmFileOpsJob* job)
{
    gboolean ret = TRUE;
    GFile *dest_dir;
    GList* l;
    FmJob* fmjob = FM_JOB(job);
    /* prepare the job, count total work needed with FmDeepCountJob */
    FmDeepCountJob* dc = fm_deep_count_job_new(job->srcs, FM_DC_JOB_DEFAULT);
    FmFolder *df;

    /* let the deep count job share the same cancellable object. */
    fm_job_set_cancellable(FM_JOB(dc), fm_job_get_cancellable(fmjob));
    fm_job_run_sync(FM_JOB(dc));
    job->total = dc->total_size;
    if(fm_job_is_cancelled(fmjob))
    {
        g_object_unref(dc);
        return FALSE;
    }
    g_object_unref(dc);
    g_debug("total size to copy: %llu", (long long unsigned int)job->total);

    dest_dir = fm_path_to_gfile(job->dest);
    /* suspend updates for destination */
    df = fm_folder_find_by_path(job->dest);
    if (df)
        fm_folder_block_updates(df);

    fm_file_ops_job_emit_prepared(job);

    for(l = fm_path_list_peek_head_link(job->srcs); !fm_job_is_cancelled(fmjob) && l; l=l->next)
    {
        FmPath* path = FM_PATH(l->data);
        GFile* src = fm_path_to_gfile(path);
        GFile* dest;
        char* tmp_basename;

        if(g_file_is_native(src) && g_file_is_native(dest_dir))
            /* both are native */
            tmp_basename = NULL;
        else if(g_file_is_native(src)) /* copy from native to virtual */
            tmp_basename = g_filename_to_utf8(fm_path_get_basename(path),
                                              -1, NULL, NULL, NULL);
            /* gvfs escapes it itself */
        else /* copy from virtual to native/virtual */
        {
            /* if we drop URI query onto native filesystem, omit query part */
            const char *basename = fm_path_get_basename(path);
            char *sub_name;

            sub_name = strchr(basename, '?');
            if (sub_name)
            {
                sub_name = g_strndup(basename, sub_name - basename);
                basename = strrchr(sub_name, G_DIR_SEPARATOR);
                if (basename)
                    basename++;
                else
                    basename = sub_name;
            }
            tmp_basename = fm_uri_subpath_to_native_subpath(basename, NULL);
            g_free(sub_name);
        }
        dest = g_file_get_child(dest_dir,
                        tmp_basename ? tmp_basename : fm_path_get_basename(path));
        g_free(tmp_basename);
        if(!_fm_file_ops_job_copy_file(job, src, NULL, dest, NULL, df))
            ret = FALSE;
        g_object_unref(src);
        g_object_unref(dest);
    }

    /* g_debug("finished: %llu, total: %llu", job->finished, job->total); */
    fm_file_ops_job_emit_percent(job);

    /* restore updates for destination */
    if (df)
    {
        fm_folder_unblock_updates(df);
        g_object_unref(df);
    }
    g_object_unref(dest_dir);
    return ret;
}
Ejemplo n.º 8
0
static gboolean _on_show_dlg(gpointer user_data)
{
    FmProgressDisplay* data = (FmProgressDisplay*)user_data;
    GtkBuilder* builder;
    GtkLabel* to;
    GtkWidget *to_label;
    FmPath* dest;
    const char* title = NULL;
    GtkTextTagTable* tag_table;

    builder = gtk_builder_new();
    tag_table = gtk_text_tag_table_new();
    gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
    gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/progress.ui", NULL);

    data->dlg = GTK_DIALOG(gtk_builder_get_object(builder, "dlg"));
    g_object_weak_ref(G_OBJECT(data->dlg), on_progress_dialog_destroy, data);

    g_signal_connect(data->dlg, "response", G_CALLBACK(on_response), data);
    /* FIXME: connect to "close" signal */

    to_label = (GtkWidget*)gtk_builder_get_object(builder, "to_label");
    to = GTK_LABEL(gtk_builder_get_object(builder, "dest"));
    data->icon = GTK_IMAGE(gtk_builder_get_object(builder, "icon"));
    data->msg = GTK_LABEL(gtk_builder_get_object(builder, "msg"));
    data->act = GTK_LABEL(gtk_builder_get_object(builder, "action"));
    data->src = GTK_LABEL(gtk_builder_get_object(builder, "src"));
    data->dest = (GtkWidget*)gtk_builder_get_object(builder, "dest");
    data->current = GTK_LABEL(gtk_builder_get_object(builder, "current"));
    data->progress = GTK_PROGRESS_BAR(gtk_builder_get_object(builder, "progress"));
    data->error_pane = (GtkWidget*)gtk_builder_get_object(builder, "error_pane");
    data->error_msg = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "error_msg"));
    data->data_transferred = GTK_LABEL(gtk_builder_get_object(builder, "data_transferred"));
    data->data_transferred_label = GTK_LABEL(gtk_builder_get_object(builder, "data_transferred_label"));
    data->remaining_time = GTK_LABEL(gtk_builder_get_object(builder, "remaining_time"));
    data->remaining_time_label = GTK_LABEL(gtk_builder_get_object(builder, "remaining_time_label"));
    data->cancel = GTK_BUTTON(gtk_builder_get_object(builder, "cancel"));
    data->suspend = GTK_BUTTON(gtk_dialog_add_button(data->dlg, _("_Pause"), 1));
    gtk_button_set_use_stock(data->suspend, FALSE);
    gtk_button_set_use_underline(data->suspend, TRUE);
    gtk_button_set_image(data->suspend,
                         gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE,
                                                  GTK_ICON_SIZE_BUTTON));
    gtk_dialog_set_alternative_button_order(data->dlg, 1, GTK_RESPONSE_CANCEL, -1);
    data->bold_tag = gtk_text_tag_new("bold");
    g_object_set(data->bold_tag, "weight", PANGO_WEIGHT_BOLD, NULL);
    gtk_text_tag_table_add(tag_table, data->bold_tag);
    data->error_buf = gtk_text_buffer_new(tag_table);
    g_object_unref(tag_table);
    gtk_text_view_set_buffer(data->error_msg, data->error_buf);

    gtk_widget_hide(GTK_WIDGET(data->icon));

    g_object_unref(builder);

    /* set the src label */
    /* FIXME: direct access to job struct! */
    if(data->job->srcs)
    {
        GList* l = fm_path_list_peek_head_link(data->job->srcs);
        int i;
        char* disp;
        FmPath* path;
        GString* str = g_string_sized_new(512);
        path = FM_PATH(l->data);
        disp = fm_path_display_basename(path);
        g_string_assign(str, disp);
        g_free(disp);
        for( i =1, l=l->next; i < 10 && l; l=l->next, ++i)
        {
            path = FM_PATH(l->data);
            g_string_append(str, _(", "));
            disp = fm_path_display_basename(path);
            g_string_append(str, disp);
            g_free(disp);
        }
        if(l)
            g_string_append(str, "...");
        gtk_label_set_text(data->src, str->str);
        gtk_widget_set_tooltip_text(GTK_WIDGET(data->src), str->str);
        g_string_free(str, TRUE);
    }

    /* FIXME: use accessor functions instead */
    /* FIXME: direct access to job struct! */
    switch(data->job->type)
    {
    /* we set title here if text is complex so may be different from
       the op_text when is translated to other languages */
    case FM_FILE_OP_MOVE:
        /* translators: it is part of "Moving files:" or "Moving xxx.txt" */
        data->op_text = _("Moving");
        break;
    case FM_FILE_OP_COPY:
        /* translators: it is part of "Copying files:" or "Copying xxx.txt" */
        data->op_text = _("Copying");
        break;
    case FM_FILE_OP_TRASH:
        /* translators: it is part of "Trashing files:" or "Trashing xxx.txt" */
        data->op_text = _("Trashing");
        break;
    case FM_FILE_OP_DELETE:
        /* translators: it is part of "Deleting files:" or "Deleting xxx.txt" */
        data->op_text = _("Deleting");
        break;
    case FM_FILE_OP_LINK:
        /* translators: it is part of "Creating link /path/xxx.txt" */
        data->op_text = _("Creating link");
        /* translators: 'In:' string is followed by destination folder path */
        gtk_label_set_markup(GTK_LABEL(to_label), _("<b>In:</b>"));
        title = _("Creating links to files");
        /* NOTE: on creating single symlink or shortcut all operation
           is done in single I/O therefore it should fit into 0.5s
           timeout and progress window will never be shown */
        break;
    case FM_FILE_OP_CHANGE_ATTR:
        /* translators: it is part of "Changing attributes of xxx.txt" */
        data->op_text = _("Changing attributes of");
        title = _("Changing attributes of files");
        /* NOTE: the same about single symlink is appliable here so
           there is no need to add never used string for translation */
        break;
    case FM_FILE_OP_UNTRASH:
        /* translators: it is part of "Restoring files:" or "Restoring xxx.txt" */
        data->op_text = _("Restoring");
        break;
    case FM_FILE_OP_NONE: ;
    }
    data->str = g_string_sized_new(64);
    if (title)
        gtk_window_set_title(GTK_WINDOW(data->dlg), title);
    else
    {
        /* note to translators: resulting string is such as "Deleting files" */
        g_string_printf(data->str, _("%s files"), data->op_text);
        gtk_window_set_title(GTK_WINDOW(data->dlg), data->str->str);
    }
    gtk_label_set_markup(data->msg, _("<b>File operation is in progress...</b>"));
    gtk_widget_show(GTK_WIDGET(data->msg));
    if (title) /* we already know the exact string */
        g_string_printf(data->str, "<b>%s:</b>", title);
    else if (fm_path_list_get_length(data->job->srcs) == 1)
        /* note to translators: resulting string is such as "Deleting file" */
        g_string_printf(data->str, _("<b>%s file:</b>"), data->op_text);
    else
        /* note to translators: resulting string is such as "Deleting files" */
        g_string_printf(data->str, _("<b>%s files:</b>"), data->op_text);
    gtk_label_set_markup(data->act, data->str->str);

    dest = fm_file_ops_job_get_dest(data->job);
    if(dest)
    {
        char* dest_str = fm_path_display_name(dest, TRUE);
        gtk_label_set_text(to, dest_str);
        gtk_widget_set_tooltip_text(GTK_WIDGET(data->dest), dest_str);
        g_free(dest_str);
    }
    else
    {
        gtk_widget_destroy(data->dest);
        gtk_widget_destroy(to_label);
    }

    gtk_window_set_transient_for(GTK_WINDOW(data->dlg), data->parent);
    gtk_window_present(GTK_WINDOW(data->dlg));

    data->delay_timeout = 0;
    return FALSE;
}