Beispiel #1
0
static void test_predefined_paths()
{
    FmPath* path;
    char* tmp;

    path = fm_path_new_for_uri("trash:///");
    g_assert(path == fm_path_get_trash());
    fm_path_unref(path);

    path = fm_path_new_for_uri("trash:///xxx");
    g_assert(path->parent == fm_path_get_trash());
    fm_path_unref(path);

    path = fm_path_new_for_uri("menu://");
    g_assert(path == fm_path_get_apps_menu());
    fm_path_unref(path);

    path = fm_path_new_for_uri("menu://applications");
    g_assert(path == fm_path_get_apps_menu());
    fm_path_unref(path);

    path = fm_path_new_for_uri("menu://applications/test/");
    g_assert(path->parent == fm_path_get_apps_menu());
    fm_path_unref(path);

/*
    path = fm_path_new_for_path(g_get_home_dir());
    g_assert(path == fm_path_get_home());
    fm_path_unref(path);

    tmp = g_build_filename(g_get_home_dir(), "xxxx", "xx", NULL);
    path = fm_path_new_for_path(tmp);
    g_debug("path->name=%s", path->parent->parent->name);
    g_assert(path->parent->parent == fm_path_get_home());
    fm_path_unref(path);
    g_free(tmp);

    path = fm_path_new_for_path(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP));
    g_assert(path == fm_path_get_desktop());
    fm_path_unref(path);

    tmp = g_build_filename(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), "xxxx", "xx", NULL);
    path = fm_path_new_for_path(tmp);
    g_assert(path->parent->parent == fm_path_get_desktop());
    fm_path_unref(path);
    g_free(tmp);
*/
}
Beispiel #2
0
void create_trash()
{
    GtkTreeIter it;
    PlaceItem* item;
    GdkPixbuf* pix;
    GFile* gf;

    gf = g_file_new_for_uri("trash:///");
    trash_monitor = fm_monitor_directory(gf, NULL);
    g_signal_connect(trash_monitor, "changed", G_CALLBACK(on_trash_changed), NULL);
    g_object_unref(gf);

    item = g_slice_new0(PlaceItem);
    item->type = PLACE_PATH;
    item->path = fm_path_ref(fm_path_get_trash());
    item->icon = fm_icon_from_name("user-trash");
    gtk_list_store_insert(model, &it, 2);
    pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size);
    gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, _("Trash"), COL_INFO, item, -1);
    g_object_unref(pix);
    trash_it = it;

    if(0 == trash_idle)
        trash_idle = g_idle_add((GSourceFunc)update_trash, NULL);
}
Beispiel #3
0
static void create_trash_item(FmPlacesModel* model)
{
    GtkTreeIter it;
    FmPlaceItem* item;
    GdkPixbuf* pix;
    GFile* gf;

    gf = g_file_new_for_uri("trash:///");
    model->trash_monitor = fm_monitor_directory(gf, NULL);
    g_signal_connect(model->trash_monitor, "changed", G_CALLBACK(on_trash_changed), model);
    g_object_unref(gf);

    item = g_slice_new0(FmPlaceItem);
    item->type = FM_PLACES_ITEM_PATH;
    item->fi = fm_file_info_new();
    item->fi->path = fm_path_ref(fm_path_get_trash());
    item->fi->icon = fm_icon_from_name("user-trash");
    gtk_list_store_insert(GTK_LIST_STORE(model), &it, 2);
    pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size);
    gtk_list_store_set(GTK_LIST_STORE(model), &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, _("Trash"), FM_PLACES_MODEL_COL_INFO, item, -1);
    g_object_unref(pix);
    model->trash_it = it;

    if(0 == model->trash_idle)
        model->trash_idle = g_idle_add((GSourceFunc)update_trash_item, model);
}
Beispiel #4
0
/**
 * fm_empty_trash
 * @parent: a window to place dialog over it
 *
 * Asks user to confirm the emptying trash can and empties it if confirmed.
 *
 * Before 0.1.15 this call had different arguments.
 *
 * Since: 0.1.0
 */
void fm_empty_trash(GtkWindow* parent)
{
    if(fm_yes_no(parent, NULL, _("Are you sure you want to empty the trash can?"), TRUE))
    {
        FmPathList* paths = fm_path_list_new();
        fm_path_list_push_tail(paths, fm_path_get_trash());
        fm_delete_files_internal(parent, paths);
        fm_path_list_unref(paths);
    }
}
Beispiel #5
0
void PlacesView::contextMenuEvent(QContextMenuEvent* event) {
  QModelIndex index = indexAt(event->pos());
  if(index.isValid() && index.parent().isValid()) {
    if(index.column() != 0) // the real item is at column 0
      index = index.sibling(index.row(), 0);

    // Do not take the ownership of the menu since
    // it will be deleted with deleteLater() upon hidden.
    // This is possibly related to #145 - https://github.com/lxde/pcmanfm-qt/issues/145
    QMenu* menu = new QMenu();
    QAction* action;
    PlacesModelItem* item = static_cast<PlacesModelItem*>(model_->itemFromIndex(index));

    if(item->type() != PlacesModelItem::Mount
        && (item->type() != PlacesModelItem::Volume
        || static_cast<PlacesModelVolumeItem*>(item)->isMounted())) {
      action = new PlacesModel::ItemAction(item->index(), tr("Open in New Tab"), menu);
      connect(action, &QAction::triggered, this, &PlacesView::onOpenNewTab);
      menu->addAction(action);
      action = new PlacesModel::ItemAction(item->index(), tr("Open in New Window"), menu);
      connect(action, &QAction::triggered, this, &PlacesView::onOpenNewWindow);
      menu->addAction(action);
    }

    switch(item->type()) {
      case PlacesModelItem::Places: {
        FmPath* path = item->path();
        if(path && fm_path_equal(fm_path_get_trash(), path)) {
          action = new PlacesModel::ItemAction(item->index(), tr("Empty Trash"), menu);
          connect(action, &QAction::triggered, this, &PlacesView::onEmptyTrash);
          menu->addAction(action);
        }
        break;
      }
      case PlacesModelItem::Bookmark: {
        // create context menu for bookmark item
        if(item->index().row() > 0) {
          action = new PlacesModel::ItemAction(item->index(), tr("Move Bookmark Up"), menu);
          connect(action, &QAction::triggered, this, &PlacesView::onMoveBookmarkUp);
          menu->addAction(action);
        }
        if(item->index().row() < model_->rowCount()) {
          action = new PlacesModel::ItemAction(item->index(), tr("Move Bookmark Down"), menu);
          connect(action, &QAction::triggered, this, &PlacesView::onMoveBookmarkDown);
          menu->addAction(action);
        }
        action = new PlacesModel::ItemAction(item->index(), tr("Rename Bookmark"), menu);
        connect(action, &QAction::triggered, this, &PlacesView::onRenameBookmark);
        menu->addAction(action);
        action = new PlacesModel::ItemAction(item->index(), tr("Remove Bookmark"), menu);
        connect(action, &QAction::triggered, this, &PlacesView::onDeleteBookmark);
        menu->addAction(action);
        break;
      }
      case PlacesModelItem::Volume: {
        PlacesModelVolumeItem* volumeItem = static_cast<PlacesModelVolumeItem*>(item);

        if(volumeItem->isMounted()) {
          action = new PlacesModel::ItemAction(item->index(), tr("Unmount"), menu);
          connect(action, &QAction::triggered, this, &PlacesView::onUnmountVolume);
        }
        else {
          action = new PlacesModel::ItemAction(item->index(), tr("Mount"), menu);
          connect(action, &QAction::triggered, this, &PlacesView::onMountVolume);
        }
        menu->addAction(action);

        if(volumeItem->canEject()) {
          action = new PlacesModel::ItemAction(item->index(), tr("Eject"), menu);
          connect(action, &QAction::triggered, this, &PlacesView::onEjectVolume);
          menu->addAction(action);
        }
        break;
      }
      case PlacesModelItem::Mount: {
        action = new PlacesModel::ItemAction(item->index(), tr("Unmount"), menu);
        connect(action, &QAction::triggered, this, &PlacesView::onUnmountMount);
        menu->addAction(action);
        break;
      }
    }
    if(menu->actions().size()) {
      menu->popup(mapToGlobal(event->pos()));
      connect(menu, &QMenu::aboutToHide, menu, &QMenu::deleteLater);
    } else {
        menu->deleteLater();
    }
  }
}
Beispiel #6
0
void PlacesView::onEmptyTrash() {
  FmPathList* files = fm_path_list_new();
  fm_path_list_push_tail(files, fm_path_get_trash());
  Fm::FileOperation::deleteFiles(files);
  fm_path_list_unref(files);
}