示例#1
0
void FolderMenu::createCreateNewMenu() {
  QMenu* createMenu = new QMenu(this);
  createNewMenu_ = createMenu;

  QAction* action = new QAction(tr("Folder"), this);
  connect(action, SIGNAL(triggered(bool)), SLOT(onCreateNewFolder()));
  createMenu->addAction(action);

  action = new QAction(tr("Blank File"), this);
  connect(action, SIGNAL(triggered(bool)), SLOT(onCreateNewFile()));
  createMenu->addAction(action);

  // add more items to "Create New" menu from templates
  GList* templates = fm_template_list_all(fm_config->only_user_templates);
  if(templates) {
    createMenu->addSeparator();
    for(GList* l = templates; l; l = l->next) {
      FmTemplate* templ = (FmTemplate*)l->data;
      /* we support directories differently */
      if(fm_template_is_directory(templ))
        continue;
      FmMimeType* mime_type = fm_template_get_mime_type(templ);
      const char* label = fm_template_get_label(templ);
      QString text = QString("%1 (%2)").arg(QString::fromUtf8(label)).arg(QString::fromUtf8(fm_mime_type_get_desc(mime_type)));
      FmIcon* icon = fm_template_get_icon(templ);
      if(!icon)
        icon = fm_mime_type_get_icon(mime_type);
      QAction* action = createMenu->addAction(IconTheme::icon(icon), text);
      action->setObjectName(QString::fromUtf8(fm_template_get_name(templ, NULL)));
      connect(action, SIGNAL(triggered(bool)), SLOT(onCreateNew()));
    }
  }
}
示例#2
0
CreateNewMenu::CreateNewMenu(QWidget* dialogParent, FmPath* dirPath, QWidget* parent):
  QMenu(parent), dialogParent_(dialogParent), dirPath_(dirPath) {
  QAction* action = new QAction(QIcon::fromTheme("folder-new"), tr("Folder"), this);
  connect(action, &QAction::triggered, this, &CreateNewMenu::onCreateNewFolder);
  addAction(action);

  action = new QAction(QIcon::fromTheme("document-new"), tr("Blank File"), this);
  connect(action, &QAction::triggered, this, &CreateNewMenu::onCreateNewFile);
  addAction(action);

  // add more items to "Create New" menu from templates
  GList* templates = fm_template_list_all(fm_config->only_user_templates);
  if(templates) {
    addSeparator();
    for(GList* l = templates; l; l = l->next) {
      FmTemplate* templ = (FmTemplate*)l->data;
      /* we support directories differently */
      if(fm_template_is_directory(templ))
        continue;
      FmMimeType* mime_type = fm_template_get_mime_type(templ);
      const char* label = fm_template_get_label(templ);
      QString text = QString("%1 (%2)").arg(QString::fromUtf8(label)).arg(QString::fromUtf8(fm_mime_type_get_desc(mime_type)));
      FmIcon* icon = fm_template_get_icon(templ);
      if(!icon)
        icon = fm_mime_type_get_icon(mime_type);
      QAction* action = addAction(IconTheme::icon(icon), text);
      action->setObjectName(QString::fromUtf8(fm_template_get_name(templ, NULL)));
      connect(action, &QAction::triggered, this, &CreateNewMenu::onCreateNew);
    }
  }
}
示例#3
0
void FilePropsDialog::initGeneralPage() {
  // update UI
  if(singleType) { // all files are of the same mime-type
    FmIcon* icon = NULL;
    // FIXME: handle custom icons for some files
    // FIXME: display special property pages for special files or
    // some specified mime-types.
    if(singleFile) { // only one file is selected.
      icon = fm_file_info_get_icon(fileInfo);
    }
    if(mimeType) {
      if(!icon) // get an icon from mime type if needed
        icon = fm_mime_type_get_icon(mimeType);
      ui->fileType->setText(QString::fromUtf8(fm_mime_type_get_desc(mimeType)));
      ui->mimeType->setText(QString::fromUtf8(fm_mime_type_get_type(mimeType)));
    }
    if(icon) {
      ui->iconButton->setIcon(IconTheme::icon(icon));
    }

    if(singleFile && fm_file_info_is_symlink(fileInfo)) {
      ui->target->setText(QString::fromUtf8(fm_file_info_get_target(fileInfo)));
    }
    else {
      ui->target->hide();
      ui->targetLabel->hide();
    }
  } // end if(singleType)
  else { // not singleType, multiple files are selected at the same time
    ui->fileType->setText(tr("Files of different types"));
    ui->target->hide();
    ui->targetLabel->hide();
  }

  // FIXME: check if all files has the same parent dir, mtime, or atime
  if(singleFile) { // only one file is selected
    FmPath* parent_path = fm_path_get_parent(fm_file_info_get_path(fileInfo));
    char* parent_str = parent_path ? fm_path_display_name(parent_path, true) : NULL;

    ui->fileName->setText(QString::fromUtf8(fm_file_info_get_disp_name(fileInfo)));
    if(parent_str) {
      ui->location->setText(QString::fromUtf8(parent_str));
      g_free(parent_str);
    }
    else
      ui->location->clear();

    ui->lastModified->setText(QString::fromUtf8(fm_file_info_get_disp_mtime(fileInfo)));

    // FIXME: need to encapsulate this in an libfm API.
    time_t atime;
    struct tm tm;
    atime = fm_file_info_get_atime(fileInfo);
    localtime_r(&atime, &tm);
    char buf[128];
    strftime(buf, sizeof(buf), "%x %R", &tm);
    ui->lastAccessed->setText(QString::fromUtf8(buf));
  }
  else {
    ui->fileName->setText(tr("Multiple Files"));
    ui->fileName->setEnabled(false);
  }

  initApplications(); // init applications combo box

  // calculate total file sizes
  fileSizeTimer = new QTimer(this);
  connect(fileSizeTimer, &QTimer::timeout, this, &FilePropsDialog::onFileSizeTimerTimeout);
  fileSizeTimer->start(600);
  g_signal_connect(deepCountJob, "finished", G_CALLBACK(onDeepCountJobFinished), this);
  gboolean ret = fm_job_run_async(FM_JOB(deepCountJob));
}
示例#4
0
static void update_ui (FmFilePropData *data)
{
    GtkImage *img =  (GtkImage*) data->icon;

    if ( data->single_type ) // all files are of the same mime-type
    {
        GIcon *icon = NULL;
        // FIXME_pcm: handle custom icons for some files

        /* FIXME_pcm: display special property pages for special files or
         * some specified mime-types. */
        if ( data->single_file ) // only one file is selected.
        {
            FmFileInfo *file_info =  (FmFileInfo*)fm_list_peek_head (data->files);

            icon = fm_file_info_get_gicon (file_info);
        }

        if (data->mime_type)
        {
            if (!icon)
            {
                FmIcon *ficon = fm_mime_type_get_icon (data->mime_type);
                if (ficon)
                    icon = ficon->gicon;
            }
            gtk_label_set_text (GTK_LABEL (data->type), fm_mime_type_get_desc (data->mime_type));
        }

        if (icon)
            gtk_image_set_from_gicon (img, icon, GTK_ICON_SIZE_DIALOG);

        if ( data->single_file && fm_file_info_is_symlink (data->file_info) )
        {
            gtk_widget_show (data->target_label);
            gtk_widget_show (data->target);
            gtk_label_set_text (GTK_LABEL (data->target), fm_file_info_get_target (data->file_info));

            // gtk_label_set_text (data->type, fm_mime_type_get_desc (data->mime_type));
        }
        else
        {
            gtk_widget_destroy (data->target_label);
            gtk_widget_destroy (data->target);
        }
    }
    else
    {
        gtk_image_set_from_stock (img, GTK_STOCK_DND_MULTIPLE, GTK_ICON_SIZE_DIALOG);
        gtk_widget_set_sensitive (data->name, FALSE);

        gtk_label_set_text (GTK_LABEL (data->type), _("Files of different types"));

        gtk_widget_destroy (data->target_label);
        gtk_widget_destroy (data->target);

        gtk_widget_destroy (data->open_with_label);
        gtk_widget_destroy (data->open_with);
        data->open_with = data->open_with_label = NULL;
    }

    // FIXME_pcm: check if all files has the same parent dir, mtime, or atime
    if ( data->single_file )
    {
        char buf[128];
        FmPath *parent = fm_path_get_parent (fm_file_info_get_path (data->file_info));
        char *parent_str = parent ? fm_path_display_name (parent, TRUE) : NULL;
        gtk_entry_set_text (GTK_ENTRY (data->name), fm_file_info_get_disp_name (data->file_info));
        if (parent_str)
        {
            gtk_label_set_text (GTK_LABEL (data->dir), parent_str);
            g_free (parent_str);
        }
        else
            gtk_label_set_text (GTK_LABEL (data->dir), "");
        gtk_label_set_text (GTK_LABEL (data->mtime), fm_file_info_get_disp_mtime (data->file_info));

        // FIXME_pcm: need to encapsulate this in an libfm API.
        strftime ( buf, sizeof ( buf ),
                   "%x %R",
                   localtime ( &data->file_info->atime ) );
        gtk_label_set_text (GTK_LABEL (data->atime), buf);
    }
    else
    {
        gtk_entry_set_text (GTK_ENTRY (data->name), _("Multiple Files"));
        gtk_widget_set_sensitive (data->name, FALSE);
    }

    update_permissions (data);

    on_timeout (data);
}