コード例 #1
0
static GtkTreeIter *
fill_list(GtkWidget *main_w)
{
  WS_DIR        *dir;             /* scanned directory */
  WS_DIRENT     *file;            /* current file */
  GList         *fl_entry;
  profile_def   *profile;
  GtkTreeView   *profile_l;
  GtkListStore  *store;
  GtkTreeIter    iter, *l_select = NULL;
  const gchar   *profile_name = get_profile_name ();
  const gchar   *profiles_dir, *name;
  gchar         *filename;

  profile_l = GTK_TREE_VIEW(g_object_get_data(G_OBJECT(main_w), E_PROF_PROFILE_L_KEY));
  store = GTK_LIST_STORE(gtk_tree_view_get_model(profile_l));

  fl_entry = add_to_profile_list(DEFAULT_PROFILE, DEFAULT_PROFILE, PROF_STAT_DEFAULT);
  gtk_list_store_append(store, &iter);
  gtk_list_store_set(store, &iter, 0, DEFAULT_PROFILE, 1, fl_entry, -1);
  if (strcmp (profile_name, DEFAULT_PROFILE)==0) {
    l_select = g_memdup(&iter, sizeof(iter));
  }

  /* fill in data */
  profiles_dir = get_profiles_dir();
  if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
    while ((file = ws_dir_read_name(dir)) != NULL) {
      name = ws_dir_get_name(file);
      filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

      if (test_for_directory(filename) == EISDIR) {
	fl_entry = add_to_profile_list(name, name, PROF_STAT_EXISTS);
	profile    = (profile_def *) fl_entry->data;
	gtk_list_store_append(store, &iter);
	gtk_list_store_set(store, &iter, 0, profile->name, 1, fl_entry, -1);

	if (profile->name) {
	  if (strcmp(profile_name, profile->name) == 0) {
	    /*
	     * XXX - We're assuming that we can just copy a GtkTreeIter
	     * and use it later without any crashes.  This may not be a
	     * valid assumption.
	     */
	    l_select = g_memdup(&iter, sizeof(iter));
	  }
	}
      }
      g_free (filename);
    }
    ws_dir_close (dir);
  }

  /* Make the current list and the edited list equal */
  copy_profile_list ();

  return l_select;
}
コード例 #2
0
ファイル: profile.c プロジェクト: ARK1988/wireshark
void
init_profile_list(void)
{
    WS_DIR        *dir;             /* scanned directory */
    WS_DIRENT     *file;            /* current file */
    const gchar   *profiles_dir, *name;
    gchar         *filename;

    empty_profile_list(TRUE);

    /* Default entry */
    add_to_profile_list(DEFAULT_PROFILE, DEFAULT_PROFILE, PROF_STAT_DEFAULT, FALSE, FALSE);

    /* Local (user) profiles */
    profiles_dir = get_profiles_dir();
    if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
        while ((file = ws_dir_read_name(dir)) != NULL) {
            name = ws_dir_get_name(file);
            filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

            if (test_for_directory(filename) == EISDIR) {
                /*fl_entry =*/ add_to_profile_list(name, name, PROF_STAT_EXISTS, FALSE, FALSE);
            }
            g_free (filename);
        }
        ws_dir_close (dir);
    }

    /* Global profiles */
    profiles_dir = get_global_profiles_dir();
    if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
        while ((file = ws_dir_read_name(dir)) != NULL) {
            name = ws_dir_get_name(file);
            filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

            if (test_for_directory(filename) == EISDIR) {
                /*fl_entry =*/ add_to_profile_list(name, name, PROF_STAT_EXISTS, TRUE, TRUE);
                /*profile = (profile_def *) fl_entry->data;*/
            }
            g_free (filename);
        }
        ws_dir_close (dir);
    }

    /* Make the current list and the edited list equal */
    copy_profile_list ();
}
コード例 #3
0
ファイル: profile_dialog.cpp プロジェクト: koyeen/wireshark
void ProfileDialog::updateWidgets()
{
    QTreeWidgetItem *item = pd_ui_->profileTreeWidget->currentItem();
    bool enable_new = false;
    bool enable_del = false;
    bool enable_copy = false;
    bool enable_ok = true;
    profile_def *current_profile = NULL;

    if (item) {
        current_profile = (profile_def *) item->data(0, Qt::UserRole).value<GList *>()->data;
        enable_new = true;
        enable_copy = true;
        if (!current_profile->is_global && current_profile->status != PROF_STAT_DEFAULT) {
            enable_del = true;
        }
    }

    if (current_profile) {
        QString profile_path = current_profile->is_global ? get_global_profiles_dir() : get_profiles_dir();
        if (current_profile->status != PROF_STAT_DEFAULT) {
            profile_path.append(QDir::separator()).append(current_profile->name);
        }
        pd_ui_->pathLabel->setText(profile_path);
        pd_ui_->pathLabel->setUrl(QUrl::fromLocalFile(profile_path).toString());
        pd_ui_->pathLabel->setToolTip(tr("Go to") + profile_path);
        pd_ui_->pathLabel->setEnabled(true);
    } else {
        pd_ui_->pathLabel->clear();
    }

    if (pd_ui_->profileTreeWidget->topLevelItemCount() > 0) {
        profile_def *profile;
        for (int i = 0; i < pd_ui_->profileTreeWidget->topLevelItemCount(); i++) {
            item = pd_ui_->profileTreeWidget->topLevelItem(i);
            profile = (profile_def *) item->data(0, Qt::UserRole).value<GList *>()->data;
            if (profile->is_global) continue;
            if (current_profile && !current_profile->is_global && profile != current_profile && strcmp(profile->name, current_profile->name) == 0) {
                item->setToolTip(0, tr("A profile already exists with that name."));
                item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid));
                enable_ok = false;
            } else {
                item->setBackground(0, QBrush());
            }
        }
    }

    pd_ui_->profileTreeWidget->resizeColumnToContents(0);
    pd_ui_->newToolButton->setEnabled(enable_new);
    pd_ui_->deleteToolButton->setEnabled(enable_del);
    pd_ui_->copyToolButton->setEnabled(enable_copy);
    ok_button_->setEnabled(enable_ok);
}
コード例 #4
0
void ProfileDialog::updateWidgets()
{
    QTreeWidgetItem *item = pd_ui_->profileTreeWidget->currentItem();
    bool enable_new = false;
    bool enable_del = false;
    bool enable_copy = false;
    bool enable_ok = true;
    profile_def *current_profile = NULL;

    if (item) {
        current_profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
        enable_new = true;
        enable_copy = true;
        if (!current_profile->is_global && !(item->font(0).strikeOut())) {
            enable_del = true;
        }
    }

    if (current_profile) {
        QString profile_path;
        QString profile_info;
        switch (current_profile->status) {
        case PROF_STAT_DEFAULT:
            if (item->font(0).strikeOut()) {
                profile_info = tr("Will be reset to default values");
            } else {
                profile_path = get_persconffile_path("", FALSE);
            }
            break;
        case PROF_STAT_EXISTS:
            {
            char* profile_dir = current_profile->is_global ? get_global_profiles_dir() : get_profiles_dir();
            profile_path = profile_dir;
            g_free(profile_dir);

            profile_path.append(QDir::separator()).append(current_profile->name);
            }
            break;
        case PROF_STAT_COPY:
            if (current_profile->reference) {
                profile_info = tr("Created from %1").arg(current_profile->reference);
                if (current_profile->from_global) {
                    profile_info.append(QString(" %1").arg(tr("(system provided)")));
                }
                break;
            }
            /* Fall Through */
        case PROF_STAT_NEW:
            profile_info = tr("Created from default settings");
            break;
        case PROF_STAT_CHANGED:
            profile_info = tr("Renamed from %1").arg(current_profile->reference);
            break;
        }
        if (!profile_path.isEmpty()) {
            pd_ui_->infoLabel->setUrl(QUrl::fromLocalFile(profile_path).toString());
            pd_ui_->infoLabel->setText(profile_path);
            pd_ui_->infoLabel->setToolTip(tr("Go to %1").arg(profile_path));
        } else {
            pd_ui_->infoLabel->clear();
            pd_ui_->infoLabel->setText(profile_info);
        }
    } else {
        pd_ui_->infoLabel->clear();
    }

    if (pd_ui_->profileTreeWidget->topLevelItemCount() > 0) {
        profile_def *profile;
        for (int i = 0; i < pd_ui_->profileTreeWidget->topLevelItemCount(); i++) {
            item = pd_ui_->profileTreeWidget->topLevelItem(i);
            profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
            if (gchar *err_msg = profile_name_is_valid(profile->name)) {
                item->setToolTip(0, err_msg);
                item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid));
                if (profile == current_profile) {
                    pd_ui_->infoLabel->setText(err_msg);
                }
                g_free(err_msg);
                enable_ok = false;
                continue;
            }
            if (profile->is_global) {
                item->setToolTip(0, tr("This is a system provided profile."));
                continue;
            }
            if (current_profile && !current_profile->is_global && profile != current_profile && strcmp(profile->name, current_profile->name) == 0) {
                item->setToolTip(0, tr("A profile already exists with this name."));
                item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid));
                if (current_profile->status != PROF_STAT_DEFAULT &&
                    current_profile->status != PROF_STAT_EXISTS)
                {
                    pd_ui_->infoLabel->setText(tr("A profile already exists with this name"));
                }
                enable_ok = false;
            } else if (item->font(0).strikeOut()) {
                item->setToolTip(0, tr("The profile will be reset to default values."));
                item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_deprecated));
            } else {
                item->setBackground(0, QBrush());
            }
        }
    }

    pd_ui_->profileTreeWidget->resizeColumnToContents(0);
    pd_ui_->newToolButton->setEnabled(enable_new);
    pd_ui_->deleteToolButton->setEnabled(enable_del);
    pd_ui_->copyToolButton->setEnabled(enable_copy);
    ok_button_->setEnabled(enable_ok);
}