void on_add_button_clicked (GtkButton *button, gpointer user_data) { current_action = NULL; edit_dlg = create_edit_dlg(); gtk_window_set_title(GTK_WINDOW(edit_dlg), _("Add Command")); // generate unique command name char name[15] = "new_cmd"; int suffix = 0; while(name_exists(name, NULL) && suffix < 1000) { // create a unique name snprintf(name, sizeof (name), "new_cmd%d", suffix); suffix++; } if (name_exists (name, NULL)) { return; } // Set default values in text fields gtk_entry_set_text( GTK_ENTRY(lookup_widget(edit_dlg, "name_entry")), name); gtk_entry_set_text( GTK_ENTRY(lookup_widget(edit_dlg, "title_entry")), "New Command"); // Set default values in check boxes gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(lookup_widget(edit_dlg, "single_check")), TRUE); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(lookup_widget(edit_dlg, "local_check")), TRUE); gtk_widget_show(edit_dlg); }
Contact ContactManager::get_contact_by_name(string name) { if(!name_exists(name)) { throw ContactMissingException(); } return name_map[name]; }
NMTestServiceInfo * nm_test_service_init (void) { NMTestServiceInfo *info; const char *args[2] = { TEST_NM_SERVICE, NULL }; GError *error = NULL; int i; info = g_malloc0 (sizeof (*info)); info->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); /* Spawn the test service. info->keepalive_fd will be a pipe to the service's * stdin; if it closes, the service will exit immediately. We use this to * make sure the service exits if the test program crashes. */ g_spawn_async_with_pipes (NULL, (char **) args, NULL, 0, NULL, NULL, &info->pid, &info->keepalive_fd, NULL, NULL, &error); g_assert_no_error (error); /* Wait until the service is registered on the bus */ for (i = 100; i > 0; i--) { if (name_exists (info->bus, "org.freedesktop.NetworkManager")) break; g_usleep (G_USEC_PER_SEC / 50); } g_assert (i > 0); /* Grab a proxy to our fake NM service to trigger tests */ info->proxy = g_dbus_proxy_new_sync (info->bus, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, NM_DBUS_SERVICE, NM_DBUS_PATH, "org.freedesktop.NetworkManager.LibnmGlibTest", NULL, &error); g_assert_no_error (error); return info; }
void nm_test_service_cleanup (NMTestServiceInfo *info) { int i; g_object_unref (info->proxy); kill (info->pid, SIGTERM); /* Wait until the bus notices the service is gone */ for (i = 100; i > 0; i--) { if (!name_exists (info->bus, "org.freedesktop.NetworkManager")) break; g_usleep (G_USEC_PER_SEC / 50); } g_assert (i > 0); g_object_unref (info->bus); close (info->keepalive_fd); memset (info, 0, sizeof (*info)); g_free (info); }
static int validate_command_edit () { const char *text; char message[256] = ""; int valid = 1; text = gtk_entry_get_text(GTK_ENTRY(lookup_widget(edit_dlg, "name_entry"))); if(is_empty(text) || name_exists(text, current_action)) { strcat(message, _("ID must be non-empty and unique.\n")); valid = 0; } text = gtk_entry_get_text(GTK_ENTRY(lookup_widget(edit_dlg, "title_entry"))); if(is_empty(text)) { strcat(message, _("Title must be non-empty.\n")); valid = 0; } text = gtk_entry_get_text(GTK_ENTRY(lookup_widget(edit_dlg, "cmd_entry"))); if(is_empty(text)) { strcat(message, _("Shell Command must be non-empty.\n")); valid = 0; } if(!valid) { GtkWidget *invalid_dlg = gtk_message_dialog_new (GTK_WINDOW(conf_dlg), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Invalid Values")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (invalid_dlg), "%s", message); gtk_window_set_transient_for(GTK_WINDOW (invalid_dlg), GTK_WINDOW (conf_dlg)); gtk_window_set_title (GTK_WINDOW (invalid_dlg), _("Invalid Values")); gtk_dialog_run (GTK_DIALOG (invalid_dlg)); gtk_widget_destroy(invalid_dlg); } return valid; }
void Setup::add_name_id(const std::string& name, Expr::Id id) { if (name_exists(name)) throw std::logic_error("Name already exists"); name_id_map_[name] = id; }