static int wallet_load_keys(struct wallet *wallet, char **errStr, struct config *cfg, enum wallet_state *wallet_state) { char *saltStr; int64 count; int n; int i; n = config_getint64(cfg, 0, "numKeys"); saltStr = config_getstring(cfg, NULL, "encryption.salt"); count = config_getint64(cfg, CRYPT_NUM_ITERATIONS_OLD, "encryption.numIterations"); if (saltStr == NULL) { *wallet_state = WALLET_PLAIN; } else { *wallet_state = WALLET_ENCRYPTED_LOCKED; } wallet_crypt_init(wallet, saltStr, count); free(saltStr); Log(LGPFX" %s wallet: %u key%s in file '%s'.\n", *wallet_state == WALLET_PLAIN ? "plain" : "encrypted", n, n > 1 ? "s" : "", wallet->filename); for (i = 0; i < n; i++) { time_t birth = config_getint64(cfg, 0, "key%u.birth", i); char *desc = config_getstring(cfg, NULL, "key%u.desc", i); char *priv = config_getstring(cfg, NULL, "key%u.privkey", i); char *pub = config_getstring(cfg, NULL, "key%u.pubkey", i); bool spendable = config_getbool(cfg, TRUE, "key%u.spendable", i); bool s; s = wallet_alloc_key(wallet, priv, pub, desc, birth, spendable); free(pub); free(priv); free(desc); if (s == 0) { Log(LGPFX" failed to load pub_key #%u\n", i); *errStr = "failed to alloc key"; goto exit; } } if (wallet->pass && *wallet_state == WALLET_ENCRYPTED_LOCKED) { *wallet_state = WALLET_ENCRYPTED_UNLOCKED; } return 0; exit: return 1; }
static void window_title_changed_cb (GtkWidget *widget, gpointer data) { DEBUG_FUNCTION ("window_title_changed_cb"); DEBUG_ASSERT (widget != NULL); DEBUG_ASSERT (data != NULL); tilda_term *tt = TILDA_TERM(data); gchar *title = get_window_title (widget); GtkWidget *label; label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (tt->tw->notebook), tt->hbox); /* We need to check if the widget that received the title change is the currently * active tab. If not we should not update the window title. */ gint page = gtk_notebook_get_current_page (GTK_NOTEBOOK (tt->tw->notebook)); GtkWidget *active_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (tt->tw->notebook), page); gboolean active = widget == active_page; guint length = (guint) config_getint ("title_max_length"); if(config_getbool("title_max_length_flag") && strlen(title) > length) { gchar *titleOffset = title + strlen(title) - length; gchar *shortTitle = g_strdup_printf ("...%s", titleOffset); gtk_label_set_text (GTK_LABEL(label), shortTitle); if (active) { gtk_window_set_title (GTK_WINDOW (tt->tw->window), shortTitle); } g_free(shortTitle); } else { gtk_label_set_text (GTK_LABEL(label), title); if (active) { gtk_window_set_title (GTK_WINDOW (tt->tw->window), title); } } g_free (title); }
/** * @force_hide: This option is used by the auto hide feature, so we can ignore the checks to focus tilda instead * of pulling up. */ void pull (struct tilda_window_ *tw, enum pull_state state, gboolean force_hide) { DEBUG_FUNCTION ("pull"); DEBUG_ASSERT (tw != NULL); DEBUG_ASSERT (state == PULL_UP || state == PULL_DOWN || state == PULL_TOGGLE); gint i; gboolean needsFocus = !tw->focus_loss_on_keypress && !gtk_window_is_active(GTK_WINDOW(tw->window)) && !force_hide && !tw->hide_non_focused; if (tw->current_state == DOWN && needsFocus) { /** * See tilda_window.c in focus_out_event_cb for an explanation about focus_loss_on_keypress * This conditional branch will only focus tilda but it does not actually pull the window up. */ TRACE (g_print("Tilda window not focused but visible\n")); gdk_x11_window_set_user_time(gtk_widget_get_window(tw->window), tomboy_keybinder_get_current_event_time()); tilda_window_set_active(tw); } else if (tw->current_state == UP && state != PULL_UP) { /* Keep things here just like they are. If you use gtk_window_present() here, you * will introduce some weird graphical glitches. Also, calling gtk_window_move() * before showing the window avoids yet more glitches. You should probably not use * gtk_window_show_all() here, as it takes a long time to execute. * * Overriding the user time here seems to work a lot better than calling * gtk_window_present_with_time() here, or at the end of the function. I have * no idea why, they should do the same thing. */ gdk_x11_window_set_user_time (gtk_widget_get_window (tw->window), tomboy_keybinder_get_current_event_time()); gtk_window_move (GTK_WINDOW(tw->window), config_getint ("x_pos"), config_getint ("y_pos")); gtk_widget_show (GTK_WIDGET(tw->window)); /* Nasty code to make metacity behave. Starting at metacity-2.22 they "fixed" the * focus stealing prevention to make the old _NET_WM_USER_TIME hack * not work anymore. This is working for now... */ tilda_window_set_active (tw); /* The window should maintain its properties when it is merely hidden, but it does * not. If you delete the following call, the window will not remain visible * on all workspaces after pull()ing it up and down a number of times. * * Note that the "Always on top" property doesn't seem to go away, only this * property (Show on all desktops) does... */ if (config_getbool ("pinned")) gtk_window_stick (GTK_WINDOW (tw->window)); if (config_getbool ("animation")) { for (i=0; i<16; i++) { gtk_window_move (GTK_WINDOW(tw->window), posIV[2][i], posIV[0][i]); gtk_window_resize (GTK_WINDOW(tw->window), posIV[3][i], posIV[1][i]); process_all_pending_gtk_events (); g_usleep (config_getint ("slide_sleep_usec")); } } debug_printf ("pull(): MOVED DOWN\n"); tw->current_state = DOWN; } else if (state != PULL_DOWN) { if (config_getbool ("animation")) { for (i=15; i>=0; i--) { gtk_window_move (GTK_WINDOW(tw->window), posIV[2][i], posIV[0][i]); gtk_window_resize (GTK_WINDOW(tw->window), posIV[3][i], posIV[1][i]); process_all_pending_gtk_events (); g_usleep (config_getint ("slide_sleep_usec")); } } /* All we have to do at this point is hide the window. * Case 1 - Animation on: The window has shrunk, just hide it * Case 2 - Animation off: Just hide the window */ gtk_widget_hide (GTK_WIDGET(tw->window)); debug_printf ("pull(): MOVED UP\n"); tw->current_state = UP; } }
/** * tilda_term_config_defaults () * * Read and set all of the defaults for this terminal from the current configuration. * * Success: return 0 * Failure: return non-zero */ static gint tilda_term_config_defaults (tilda_term *tt) { DEBUG_FUNCTION ("tilda_term_config_defaults"); DEBUG_ASSERT (tt != NULL); gdouble transparency_level = 0.0; GdkRGBA fg, bg, cc; gchar* word_chars; gint i; gint cursor_shape; /** Colors & Palette **/ bg.red = GUINT16_TO_FLOAT(config_getint ("back_red")); bg.green = GUINT16_TO_FLOAT(config_getint ("back_green")); bg.blue = GUINT16_TO_FLOAT(config_getint ("back_blue")); bg.alpha = 1.0; fg.red = GUINT16_TO_FLOAT(config_getint ("text_red")); fg.green = GUINT16_TO_FLOAT(config_getint ("text_green")); fg.blue = GUINT16_TO_FLOAT(config_getint ("text_blue")); fg.alpha = 1.0; cc.red = GUINT16_TO_FLOAT(config_getint ("cursor_red")); cc.green = GUINT16_TO_FLOAT(config_getint ("cursor_green")); cc.blue = GUINT16_TO_FLOAT(config_getint ("cursor_blue")); cc.alpha = 1.0; for(i = 0;i < TERMINAL_PALETTE_SIZE; i++) { current_palette[i].red = GUINT16_TO_FLOAT(config_getnint ("palette", i*3)); current_palette[i].green = GUINT16_TO_FLOAT(config_getnint ("palette", i*3+1)); current_palette[i].blue = GUINT16_TO_FLOAT(config_getnint ("palette", i*3+2)); current_palette[i].alpha = 1.0; } vte_terminal_set_colors_rgba (VTE_TERMINAL(tt->vte_term), &fg, &bg, current_palette, TERMINAL_PALETTE_SIZE); /** Bells **/ vte_terminal_set_audible_bell (VTE_TERMINAL(tt->vte_term), config_getbool ("bell")); vte_terminal_set_visible_bell (VTE_TERMINAL(tt->vte_term), config_getbool ("bell")); /** Cursor **/ vte_terminal_set_cursor_blink_mode (VTE_TERMINAL(tt->vte_term), (config_getbool ("blinks"))?VTE_CURSOR_BLINK_ON:VTE_CURSOR_BLINK_OFF); vte_terminal_set_color_cursor_rgba (VTE_TERMINAL(tt->vte_term), &cc); cursor_shape = config_getint("cursor_shape"); if (cursor_shape < 0 || cursor_shape > 2) { config_setint("cursor_shape", 0); cursor_shape = 0; } vte_terminal_set_cursor_shape(VTE_TERMINAL(tt->vte_term), (VteTerminalCursorShape)cursor_shape); /** Scrolling **/ vte_terminal_set_scroll_background (VTE_TERMINAL(tt->vte_term), config_getbool ("scroll_background")); vte_terminal_set_scroll_on_output (VTE_TERMINAL(tt->vte_term), config_getbool ("scroll_on_output")); vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(tt->vte_term), config_getbool ("scroll_on_key")); /** Mouse **/ vte_terminal_set_mouse_autohide (VTE_TERMINAL(tt->vte_term), FALSE); /* TODO: make this configurable */ /** Text Properties **/ vte_terminal_set_allow_bold (VTE_TERMINAL(tt->vte_term), config_getbool ("bold")); gtk_widget_set_double_buffered (tt->vte_term, config_getbool("double_buffer")); PangoFontDescription *description = pango_font_description_from_string (config_getstr ("font")); vte_terminal_set_font (VTE_TERMINAL (tt->vte_term), description); /** Scrollback **/ vte_terminal_set_scrollback_lines (VTE_TERMINAL(tt->vte_term), config_getbool("scroll_history_infinite") ? -1 : config_getint ("lines")); /** Keys **/ switch (config_getint ("backspace_key")) { case ASCII_DELETE: vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_DELETE); break; case DELETE_SEQUENCE: vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_DELETE_SEQUENCE); break; case ASCII_BACKSPACE: vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_BACKSPACE); break; case AUTO: default: vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_AUTO); break; } switch (config_getint ("delete_key")) { case ASCII_DELETE: vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_DELETE); break; case DELETE_SEQUENCE: vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_DELETE_SEQUENCE); break; case ASCII_BACKSPACE: vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_BACKSPACE); break; case AUTO: default: vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_AUTO); break; } /** Word chars **/ word_chars = config_getstr ("word_chars"); if (NULL == word_chars || '\0' == *word_chars) { word_chars = DEFAULT_WORD_CHARS; } vte_terminal_set_word_chars (VTE_TERMINAL(tt->vte_term), word_chars); /** Background **/ if (config_getbool ("use_image")) vte_terminal_set_background_image_file (VTE_TERMINAL(tt->vte_term), config_getstr ("image")); else vte_terminal_set_background_image_file (VTE_TERMINAL(tt->vte_term), NULL); transparency_level = ((gdouble) config_getint ("transparency"))/100; if (config_getbool ("enable_transparency") && transparency_level > 0) { vte_terminal_set_background_saturation (VTE_TERMINAL (tt->vte_term), transparency_level); vte_terminal_set_opacity (VTE_TERMINAL (tt->vte_term), (1.0 - transparency_level) * 0xffff); vte_terminal_set_background_transparent (VTE_TERMINAL(tt->vte_term), !tt->tw->have_argb_visual); } return 0; }
/* Fork a shell into the VTE Terminal * * @param tt the tilda_term to fork into * * SUCCESS: return 0 * FAILURE: return non-zero */ static gint start_shell (struct tilda_term_ *tt, gboolean ignore_custom_command, const char* working_dir) { DEBUG_FUNCTION ("start_shell"); DEBUG_ASSERT (tt != NULL); gint ret; gint argc; gchar **argv; GError *error = NULL; gchar *default_command; if (working_dir == NULL || config_getbool ("inherit_working_dir") == FALSE) { working_dir = config_getstr ("working_dir"); } if (config_getbool ("run_command") && !ignore_custom_command) { ret = g_shell_parse_argv (config_getstr ("command"), &argc, &argv, &error); /* Check for error */ if (ret == FALSE) { g_printerr (_("Problem parsing custom command: %s\n"), error->message); g_printerr (_("Launching default shell instead\n")); g_error_free (error); goto launch_default_shell; } char **envv = malloc(2*sizeof(void *)); envv[0] = getenv("PATH"); envv[1] = NULL; ret = vte_terminal_fork_command_full (VTE_TERMINAL (tt->vte_term), VTE_PTY_DEFAULT, /* VtePtyFlags pty_flags */ working_dir, /* const char *working_directory */ argv, /* char **argv */ envv, /* char **envv */ G_SPAWN_SEARCH_PATH, /* GSpawnFlags spawn_flags */ NULL, /* GSpawnChildSetupFunc child_setup */ NULL, /* gpointer child_setup_data */ &tt->pid, /* GPid *child_pid */ NULL /* GError **error */ ); g_strfreev (argv); g_free (envv); /* Check for error */ if (ret == FALSE) { g_printerr (_("Unable to launch custom command: %s\n"), config_getstr ("command")); g_printerr (_("Launching default shell instead\n")); goto launch_default_shell; } return 0; /* SUCCESS: the early way out */ } launch_default_shell: /* If we have dropped to the default shell before, then this time, we * do not spawn a new shell, but instead close the current shell. This will * cause the current tab to close. */ if (tt->dropped_to_default_shell) { gint index = gtk_notebook_page_num (GTK_NOTEBOOK(tt->tw->notebook), tt->hbox); tilda_window_close_tab (tt->tw, index, FALSE); return 0; } if (ignore_custom_command) { tt->dropped_to_default_shell = TRUE; } /* No custom command, get it from the environment */ default_command = (gchar *) g_getenv ("SHELL"); /* Check for error */ if (default_command == NULL) default_command = "/bin/sh"; /* We need to create a NULL terminated list of arguments. * The first item is the command to execute in the shell, in this * case there are no further arguments being passed. */ GSpawnFlags flags = 0; gchar* argv1 = NULL; if(config_getbool("command_login_shell")) { argv1 = g_strdup_printf("-%s", default_command); argv = malloc(3 * sizeof(void *)); argv[0] = default_command; argv[1] = argv1; argv[2] = NULL; /* This is needed so that argv[1] becomes the argv[0] of the new process. Otherwise * glib just duplicates argv[0] when it executes the command and it is not possible * to modify the argv[0] that the new command sees. */ flags |= G_SPAWN_FILE_AND_ARGV_ZERO; } else { argv = malloc(1 * sizeof(void *)); argv[0] = default_command; argv[1] = NULL; } ret = vte_terminal_fork_command_full (VTE_TERMINAL (tt->vte_term), VTE_PTY_DEFAULT, /* VtePtyFlags pty_flags */ working_dir, /* const char *working_directory */ argv, /* char **argv */ NULL, /* char **envv */ flags, /* GSpawnFlags spawn_flags */ NULL, /* GSpawnChildSetupFunc child_setup */ NULL, /* gpointer child_setup_data */ &tt->pid, /* GPid *child_pid */ NULL /* GError **error */ ); g_free(argv1); g_free (argv); if (ret == -1) { g_printerr (_("Unable to launch default shell: %s\n"), default_command); return ret; } return 0; }
/* Fork a shell into the VTE Terminal * * @param tt the tilda_term to fork into * * SUCCESS: return 0 * FAILURE: return non-zero */ static gint start_shell (struct tilda_term_ *tt) { DEBUG_FUNCTION ("start_shell"); DEBUG_ASSERT (tt != NULL); gint ret; gint argc; gchar **argv; GError *error = NULL; gchar *default_command; if (config_getbool ("run_command")) { ret = g_shell_parse_argv (config_getstr ("command"), &argc, &argv, &error); /* Check for error */ if (ret == FALSE) { g_printerr (_("Problem parsing custom command: %s\n"), error->message); g_printerr (_("Launching default shell instead\n")); g_error_free (error); goto launch_default_shell; } char **envv = malloc(2*sizeof(void *)); envv[0] = getenv("PATH"); envv[1] = NULL; ret = vte_terminal_fork_command_full (VTE_TERMINAL (tt->vte_term), VTE_PTY_DEFAULT, /* VtePtyFlags pty_flags */ config_getstr ("working_dir"), /* const char *working_directory */ argv, /* char **argv */ envv, /* char **envv */ G_SPAWN_SEARCH_PATH, /* GSpawnFlags spawn_flags */ NULL, /* GSpawnChildSetupFunc child_setup */ NULL, /* gpointer child_setup_data */ NULL, /* GPid *child_pid */ NULL /* GError **error */ ); g_strfreev (argv); g_free (envv); /* Check for error */ if (ret == -1) { g_printerr (_("Unable to launch custom command: %s\n"), config_getstr ("command")); g_printerr (_("Launching default shell instead\n")); goto launch_default_shell; } return 0; /* SUCCESS: the early way out */ } launch_default_shell: /* No custom command, get it from the environment */ default_command = (gchar *) g_getenv ("SHELL"); /* Check for error */ if (default_command == NULL) default_command = "/bin/sh"; /* We need to create a NULL terminated list of arguments. * The first item is the command to execute in the shell, in this * case there are no further arguments being passed. */ argv = malloc(2 * sizeof(void *)); argv[0] = default_command; argv[1] = NULL; ret = vte_terminal_fork_command_full (VTE_TERMINAL (tt->vte_term), VTE_PTY_DEFAULT, /* VtePtyFlags pty_flags */ config_getstr ("working_dir"), /* const char *working_directory */ argv, /* char **argv */ NULL, /* char **envv */ 0, /* GSpawnFlags spawn_flags */ NULL, /* GSpawnChildSetupFunc child_setup */ NULL, /* gpointer child_setup_data */ NULL, /* GPid *child_pid */ NULL /* GError **error */ ); g_free (argv); if (ret == -1) { g_printerr (_("Unable to launch default shell: %s\n"), default_command); return ret; } return 0; }