static void wx_gtk_insert_text_callback(GtkEditable *editable, const gchar * new_text, gint new_text_length, gint * position, wxTextEntry *text) { GtkEntry *entry = GTK_ENTRY (editable); #if GTK_CHECK_VERSION(3,0,0) || defined(GSEAL_ENABLE) const int text_max_length = gtk_entry_buffer_get_max_length(gtk_entry_get_buffer(entry)); #else const int text_max_length = entry->text_max_length; #endif bool handled = false; // check that we don't overflow the max length limit if we have it if ( text_max_length ) { const int text_length = GetEntryTextLength(entry); // We can't use new_text_length as it is in bytes while we want to count // characters (in first approximation, anyhow...). if ( text_length + g_utf8_strlen(new_text, -1) > text_max_length ) { // Prevent the new text from being inserted. handled = true; // Currently we don't insert anything at all, but it would be better to // insert as many characters as would fit into the text control and // only discard the rest. // Notify the user code about overflow. text->SendMaxLenEvent(); } } // Check if we have to convert all input to upper-case if ( !handled && text->GTKIsUpperCase() ) { const wxGtkString upper(g_utf8_strup(new_text, new_text_length)); // Use the converted text to generate events if ( !text->GTKEntryOnInsertText(upper) ) { // Event not handled, so do insert the text: we have to do it // ourselves to use the upper-case version of it // Prevent recursive call to this handler again g_signal_handlers_block_by_func ( editable, (gpointer)wx_gtk_insert_text_callback, text ); gtk_editable_insert_text(editable, upper, strlen(upper), position); g_signal_handlers_unblock_by_func ( editable, (gpointer)wx_gtk_insert_text_callback, text ); } // Don't call the default handler in any case, either the event was // handled in the user code or we've already inserted the text. handled = true; } if ( !handled && text->GTKEntryOnInsertText(new_text) ) { // If we already handled the new text insertion, don't do it again. handled = true; } if ( handled ) { // We must update the position to point after the newly inserted text, // as expected by GTK+. *position = text->GetInsertionPoint(); g_signal_stop_emission_by_name (editable, "insert_text"); } }
static gboolean lines_match (const GtkTextIter *start, const gchar **lines, gboolean visible_only, gboolean slice, GtkTextIter *match_start, GtkTextIter *match_end) { GtkTextIter next; gchar *line_text; const gchar *found; gint offset; if (*lines == NULL || **lines == '\0') { if (match_start) *match_start = *start; if (match_end) *match_end = *start; return TRUE; } next = *start; gtk_text_iter_forward_line (&next); /* No more text in buffer, but *lines is nonempty */ if (gtk_text_iter_equal (start, &next)) return FALSE; if (slice) { if (visible_only) line_text = gtk_text_iter_get_visible_slice (start, &next); else line_text = gtk_text_iter_get_slice (start, &next); } else { if (visible_only) line_text = gtk_text_iter_get_visible_text (start, &next); else line_text = gtk_text_iter_get_text (start, &next); } if (match_start) /* if this is the first line we're matching */ { found = g_utf8_strcasestr (line_text, *lines); } else { /* If it's not the first line, we have to match from the * start of the line. */ if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text), strlen (*lines))) found = line_text; else found = NULL; } if (found == NULL) { g_free (line_text); return FALSE; } /* Get offset to start of search string */ offset = g_utf8_strlen (line_text, found - line_text); next = *start; /* If match start needs to be returned, set it to the * start of the search string. */ forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE); if (match_start) { *match_start = next; } /* Go to end of search string */ forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE); g_free (line_text); ++lines; if (match_end) *match_end = next; /* pass NULL for match_start, since we don't need to find the * start again. */ return lines_match (&next, lines, visible_only, slice, NULL, match_end); }
static glong string_get_length (const char* self) { glong result; g_return_val_if_fail (self != NULL, 0L); result = g_utf8_strlen (self, -1); return result; }
gunichar * _g_utf8_normalize_wc (const gchar *str, gssize max_len, GNormalizeMode mode) { gsize n_wc; gunichar *wc_buffer; const char *p; gsize last_start; gboolean do_compat = (mode == G_NORMALIZE_NFKC || mode == G_NORMALIZE_NFKD); gboolean do_compose = (mode == G_NORMALIZE_NFC || mode == G_NORMALIZE_NFKC); n_wc = 0; p = str; while ((max_len < 0 || p < str + max_len) && *p) { const gchar *decomp; gunichar wc = g_utf8_get_char (p); if (wc >= SBase && wc < SBase + SCount) { gsize result_len; decompose_hangul (wc, NULL, &result_len); n_wc += result_len; } else { decomp = find_decomposition (wc, do_compat); if (decomp) n_wc += g_utf8_strlen (decomp, -1); else n_wc++; } p = g_utf8_next_char (p); } wc_buffer = g_new (gunichar, n_wc + 1); last_start = 0; n_wc = 0; p = str; while ((max_len < 0 || p < str + max_len) && *p) { gunichar wc = g_utf8_get_char (p); const gchar *decomp; int cc; gsize old_n_wc = n_wc; if (wc >= SBase && wc < SBase + SCount) { gsize result_len; decompose_hangul (wc, wc_buffer + n_wc, &result_len); n_wc += result_len; } else { decomp = find_decomposition (wc, do_compat); if (decomp) { const char *pd; for (pd = decomp; *pd != '\0'; pd = g_utf8_next_char (pd)) wc_buffer[n_wc++] = g_utf8_get_char (pd); } else wc_buffer[n_wc++] = wc; } if (n_wc > 0) { cc = COMBINING_CLASS (wc_buffer[old_n_wc]); if (cc == 0) { g_unicode_canonical_ordering (wc_buffer + last_start, n_wc - last_start); last_start = old_n_wc; } } p = g_utf8_next_char (p); } if (n_wc > 0) { g_unicode_canonical_ordering (wc_buffer + last_start, n_wc - last_start); last_start = n_wc; } wc_buffer[n_wc] = 0; /* All decomposed and reordered */ if (do_compose && n_wc > 0) { gsize i, j; int last_cc = 0; last_start = 0; for (i = 0; i < n_wc; i++) { int cc = COMBINING_CLASS (wc_buffer[i]); if (i > 0 && (last_cc == 0 || last_cc < cc) && combine (wc_buffer[last_start], wc_buffer[i], &wc_buffer[last_start])) { for (j = i + 1; j < n_wc; j++) wc_buffer[j-1] = wc_buffer[j]; n_wc--; i--; if (i == last_start) last_cc = 0; else last_cc = COMBINING_CLASS (wc_buffer[i-1]); continue; } if (cc == 0) last_start = i; last_cc = cc; } } wc_buffer[n_wc] = 0; return wc_buffer; }
WTextItem FontSupport::measureText(const WFont& font, const WString& text, double maxWidth, bool wordWrap) { PANGO_LOCK; enabledFontFormats = enabledFontFormats_; /* * Note: accurate measuring on a bitmap requires that the transformation * is applied, because hinting may push chars to boundaries e.g. when * rotated (or scaled too?) */ std::string utf8 = text.toUTF8(); const char *s = utf8.c_str(); if (wordWrap) { int utflen = g_utf8_strlen(s, -1); PangoLogAttr *attrs = new PangoLogAttr[utflen + 1]; PangoLanguage *language = pango_language_from_string("en-US"); pango_get_log_attrs(s, utf8.length(), -1, language, attrs, utflen + 1); double w = 0, nextW = -1; int current = 0; int measured = 0; int end = 0; bool maxWidthReached = false; for (int i = 0; i < utflen + 1; ++i) { if (i == utflen || attrs[i].is_line_break) { int cend = g_utf8_offset_to_pointer(s, end) - s; WTextItem ti = measureText(font, WString::fromUTF8(utf8.substr(measured, cend - measured)), -1, false); if (isEpsilonMore(w + ti.width(), maxWidth)) { nextW = ti.width(); maxWidthReached = true; break; } else { measured = cend; current = g_utf8_offset_to_pointer(s, i) - s; w += ti.width(); if (i == utflen) { w += measureText(font, WString::fromUTF8(utf8.substr(measured)), -1, false).width(); measured = utf8.length(); } } } if (!attrs[i].is_white) end = i + 1; } delete[] attrs; if (maxWidthReached) { return WTextItem(WString::fromUTF8(utf8.substr(0, current)), w, nextW); } else { /* * For some reason, the sum of the individual widths is a bit less * (for longer stretches of text), so we re-measure it ! */ w = measureText(font, WString::fromUTF8(utf8.substr(0, measured)), -1, false).width(); return WTextItem(text, w); } } else { std::vector<PangoGlyphString *> glyphs; int width; GList *items = layoutText(font, utf8, glyphs, width); double w = pangoUnitsToDouble(width); for (unsigned i = 0; i < glyphs.size(); ++i) pango_glyph_string_free(glyphs[i]); g_list_foreach(items, (GFunc) pango_item_free, nullptr); g_list_free(items); return WTextItem(text, w); } }
static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) { DocInfo *dinfo = user_data; GeanyEditor *editor; cairo_t *cr; gdouble width, height; gdouble x = 0.0, y = 0.0; /*gint layout_h;*/ gint count; GString *str; if (dinfo == NULL || page_nr >= dinfo->n_pages) return; editor = dinfo->doc->editor; if (dinfo->n_pages > 0) { gdouble fraction = (page_nr + 1) / (gdouble) dinfo->n_pages; gchar *text = g_strdup_printf(_("Page %d of %d"), page_nr, dinfo->n_pages); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_widgets.progressbar), fraction); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), text); g_free(text); } #ifdef GEANY_PRINT_DEBUG geany_debug("draw_page = %d, pages = %d, (real) lines_per_page = %d", page_nr, dinfo->n_pages, dinfo->lines_per_page); #endif str = g_string_sized_new(256); cr = gtk_print_context_get_cairo_context(context); width = gtk_print_context_get_width(context); height = gtk_print_context_get_height(context); cairo_set_source_rgb(cr, 0, 0, 0); #ifdef GEANY_PRINT_DEBUG cairo_set_line_width(cr, 0.2); cairo_rectangle(cr, 0, 0, width, height); cairo_stroke(cr); #endif cairo_move_to(cr, 0, 0); pango_layout_set_width(dinfo->layout, width * PANGO_SCALE); pango_layout_set_alignment(dinfo->layout, PANGO_ALIGN_LEFT); pango_layout_set_ellipsize(dinfo->layout, FALSE); pango_layout_set_justify(dinfo->layout, FALSE); if (printing_prefs.print_page_header) add_page_header(dinfo, cr, width, page_nr); count = 0; /* the actual line counter for the current page, might be different from * dinfo->cur_line due to possible line breaks */ while (count < dinfo->lines_per_page) { gchar c = 'a'; gint style = -1; PangoAttrList *layout_attr; PangoAttribute *attr; gint colours[3] = { 0 }; gboolean add_linenumber = TRUE; gboolean at_eol; while (count < dinfo->lines_per_page && c != '\0') { at_eol = FALSE; g_string_erase(str, 0, str->len); /* clear the string */ /* line numbers */ if (printing_prefs.print_line_numbers && add_linenumber) { /* if we had a wrapped line on the last page which needs to be continued, don't * add a line number */ if (dinfo->long_line) { add_linenumber = FALSE; } else { gchar *line_number = NULL; gint cur_line_number_margin = get_line_numbers_arity(dinfo->cur_line + 1); gchar *fill = g_strnfill( dinfo->max_line_number_margin - cur_line_number_margin - 1, ' '); line_number = g_strdup_printf("%s%d ", fill, dinfo->cur_line + 1); g_string_append(str, line_number); dinfo->cur_line++; /* increase document line */ add_linenumber = FALSE; style = STYLE_LINENUMBER; c = 'a'; /* dummy value */ g_free(fill); g_free(line_number); } } /* data */ else { style = sci_get_style_at(dinfo->doc->editor->sci, dinfo->cur_pos); c = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos); if (c == '\0' || style == -1) { /* if c gets 0, we are probably out of document boundaries, * so stop to break out of outer loop */ count = dinfo->lines_per_page; break; } dinfo->cur_pos++; /* convert tabs to spaces which seems to be better than using Pango tabs */ if (c == '\t') { gint tab_width = sci_get_tab_width(editor->sci); gchar *s = g_strnfill(tab_width, ' '); g_string_append(str, s); g_free(s); } /* don't add line breaks, they are handled manually below */ else if (c == '\r' || c == '\n') { gchar c_next = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos); at_eol = TRUE; if (c == '\r' && c_next == '\n') dinfo->cur_pos++; /* skip LF part of CR/LF */ } else { g_string_append_c(str, c); /* finally add the character */ /* handle UTF-8: since we add char by char (better: byte by byte), we need to * keep UTF-8 characters together(e.g. two bytes for one character) * the input is always UTF-8 and c is signed, so all non-Ascii * characters are less than 0 and consist of all bytes less than 0. * style doesn't change since it is only one character with multiple bytes. */ while (c < 0) { c = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos); if (c < 0) { /* only add the byte when it is part of the UTF-8 character * otherwise we could add e.g. a '\n' and it won't be visible in the * printed document */ g_string_append_c(str, c); dinfo->cur_pos++; } } } } if (! at_eol) { /* set text */ pango_layout_set_text(dinfo->layout, str->str, -1); /* attributes */ layout_attr = pango_attr_list_new(); /* foreground colour */ get_rgb_values(dinfo->styles[style][FORE], &colours[0], &colours[1], &colours[2]); attr = pango_attr_foreground_new(colours[0], colours[1], colours[2]); ADD_ATTR(layout_attr, attr); /* background colour */ get_rgb_values(dinfo->styles[style][BACK], &colours[0], &colours[1], &colours[2]); attr = pango_attr_background_new(colours[0], colours[1], colours[2]); ADD_ATTR(layout_attr, attr); /* bold text */ if (dinfo->styles[style][BOLD]) { attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD); ADD_ATTR(layout_attr, attr); } /* italic text */ if (dinfo->styles[style][ITALIC]) { attr = pango_attr_style_new(PANGO_STYLE_ITALIC); ADD_ATTR(layout_attr, attr); } pango_layout_set_attributes(dinfo->layout, layout_attr); pango_layout_context_changed(dinfo->layout); pango_attr_list_unref(layout_attr); } cairo_get_current_point(cr, &x, &y); /* normal line break at eol character in document */ if (at_eol) { /*pango_layout_get_size(dinfo->layout, NULL, &layout_h);*/ /*cairo_move_to(cr, 0, y + (gdouble)layout_h / PANGO_SCALE);*/ cairo_move_to(cr, 0, y + dinfo->line_height); count++; /* we added a new document line so request a new line number */ add_linenumber = TRUE; } else { gint x_offset = 0; /* maybe we need to force a line break because of too long line */ if (x >= (width - dinfo->font_width)) { /* don't start the line at horizontal origin because we need to skip the * line number margin */ if (printing_prefs.print_line_numbers) { x_offset = (dinfo->max_line_number_margin + 1) * dinfo->font_width; } /*pango_layout_get_size(dinfo->layout, NULL, &layout_h);*/ /*cairo_move_to(cr, x_offset, y + (gdouble)layout_h / PANGO_SCALE);*/ /* this is faster but not exactly the same as above */ cairo_move_to(cr, x_offset, y + dinfo->line_height); cairo_get_current_point(cr, &x, &y); count++; } if (count < dinfo->lines_per_page) { /* str->len is counted in bytes not characters, so use g_utf8_strlen() */ x_offset = (g_utf8_strlen(str->str, -1) * dinfo->font_width); if (dinfo->long_line && count == 0) { x_offset = (dinfo->max_line_number_margin + 1) * dinfo->font_width; dinfo->long_line = FALSE; } pango_cairo_show_layout(cr, dinfo->layout); cairo_move_to(cr, x + x_offset, y); } else /* we are on a wrapped line but we are out of lines on this page, so continue * the current line on the next page and remember to continue in current line */ dinfo->long_line = TRUE; } } } if (printing_prefs.print_line_numbers) { /* print a thin line between the line number margin and the data */ gint y_start = 0; if (printing_prefs.print_page_header) y_start = (dinfo->line_height * 3) - 2; /* "- 2": to connect the line number line to * the page header frame */ cairo_set_line_width(cr, 0.3); cairo_move_to(cr, (dinfo->max_line_number_margin * dinfo->font_width) + 1, y_start); cairo_line_to(cr, (dinfo->max_line_number_margin * dinfo->font_width) + 1, y + dinfo->line_height); /* y is last added line, we reuse it */ cairo_stroke(cr); } if (printing_prefs.print_page_numbers) { gchar *line = g_strdup_printf("<small>- %d -</small>", page_nr + 1); pango_layout_set_markup(dinfo->layout, line, -1); pango_layout_set_alignment(dinfo->layout, PANGO_ALIGN_CENTER); cairo_move_to(cr, 0, height - dinfo->line_height); pango_cairo_show_layout(cr, dinfo->layout); g_free(line); #ifdef GEANY_PRINT_DEBUG cairo_set_line_width(cr, 0.3); cairo_move_to(cr, 0, height - (1.25 * dinfo->line_height)); cairo_line_to(cr, width - 1, height - (1.25 * dinfo->line_height)); cairo_stroke(cr); #endif } g_string_free(str, TRUE); }
int project_edit_dialog_save_data() { g_print("project_edit_dialog_save_data()\n"); GtkTreeIter iter_status; // Check values if (g_utf8_strlen(gtk_entry_get_text(GTK_ENTRY(project_edit_entry_name)), -1) <= 0) { GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window_project_edit), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "The project name is needed."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return -1; } if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(project_edit_combo_status), &iter_status)) { GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window_project_edit), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "The status is needed."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return -1; } // Status gchar *status_id; GtkTreeModel *status_model = gtk_combo_box_get_model(GTK_COMBO_BOX(project_edit_combo_status)); gtk_tree_model_get(status_model, &iter_status, 1, &status_id, -1); g_print("Selected status: %s\n", status_id); // Mount SQL command char *error_message = 0; sqlite3 *db = database_open(); if (db == NULL) { g_print("Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return -1; } gchar *sql_command = g_strdup_printf("UPDATE project " "SET name = \"%s\", " "status = \"%s\" " "WHERE project_id = \"%d\"", gtk_entry_get_text(GTK_ENTRY(project_edit_entry_name)), status_id, project_edit_dialog_project_id); g_print("SQL INSERT command: %s\n", sql_command); int rc = sqlite3_exec(db, sql_command, NULL, 0, &error_message); if (rc != SQLITE_OK) { gchar *user_message = g_strdup_printf("Database error: %s\n", error_message); GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window_project_edit), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, user_message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); sqlite3_free(error_message); sqlite3_free(user_message); } g_free(sql_command); sqlite3_close(db); // Reload the list project_main_dialog_load_list(); // Reload issue list main_dialog_load_issue_list(); // Close this dialog project_edit_dialog_close(); return 0; }
static guint gtk_entry_buffer_normal_insert_text (GtkEntryBuffer *buffer, guint position, const gchar *chars, guint n_chars) { GtkEntryBufferPrivate *pv = buffer->priv; gsize prev_size; gsize n_bytes; gsize at; n_bytes = g_utf8_offset_to_pointer (chars, n_chars) - chars; /* Need more memory */ if (n_bytes + pv->normal_text_bytes + 1 > pv->normal_text_size) { gchar *et_new; prev_size = pv->normal_text_size; /* Calculate our new buffer size */ while (n_bytes + pv->normal_text_bytes + 1 > pv->normal_text_size) { if (pv->normal_text_size == 0) pv->normal_text_size = MIN_SIZE; else { if (2 * pv->normal_text_size < GTK_ENTRY_BUFFER_MAX_SIZE) pv->normal_text_size *= 2; else { pv->normal_text_size = GTK_ENTRY_BUFFER_MAX_SIZE; if (n_bytes > pv->normal_text_size - pv->normal_text_bytes - 1) { n_bytes = pv->normal_text_size - pv->normal_text_bytes - 1; n_bytes = g_utf8_find_prev_char (chars, chars + n_bytes + 1) - chars; n_chars = g_utf8_strlen (chars, n_bytes); } break; } } } /* Could be a password, so can't leave stuff in memory. */ et_new = g_malloc (pv->normal_text_size); memcpy (et_new, pv->normal_text, MIN (prev_size, pv->normal_text_size)); trash_area (pv->normal_text, prev_size); g_free (pv->normal_text); pv->normal_text = et_new; } /* Actual text insertion */ at = g_utf8_offset_to_pointer (pv->normal_text, position) - pv->normal_text; g_memmove (pv->normal_text + at + n_bytes, pv->normal_text + at, pv->normal_text_bytes - at); memcpy (pv->normal_text + at, chars, n_bytes); /* Book keeping */ pv->normal_text_bytes += n_bytes; pv->normal_text_chars += n_chars; pv->normal_text[pv->normal_text_bytes] = '\0'; gtk_entry_buffer_emit_inserted_text (buffer, position, chars, n_chars); return n_chars; }
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) { gint length_passed, i; gunichar c; gchar list_of_letters[255]; gchar *str; if(!gcomprisBoard) return FALSE; /* i suppose even numbers are passed through IM_context */ if ((commit_str == NULL) && (preedit_str == NULL)) return FALSE; gchar *string_passed; if (commit_str) string_passed = commit_str; else string_passed = preedit_str; str = g_strdup(string_passed); length_passed = g_utf8_strlen(string_passed, -1); for (i=0; i < length_passed; i++){ c = g_utf8_get_char (string_passed); if (is_falling_letter(c)){ gc_im_reset(); return TRUE; } /* if uppercase_only is set we do not care about upper or lower case at all */ gint level_uppercase; if (uppercase_only) level_uppercase = 10; else level_uppercase = 3; /* for 2 (or all) first level don't care abour uppercase/lowercase */ if ((gcomprisBoard->level < level_uppercase) && (is_falling_letter(g_unichar_toupper(c)))){ gc_im_reset(); return TRUE; } string_passed = g_utf8_next_char (string_passed); } list_of_letters[0] = '\0'; /* We have to loop to concat the letters */ g_hash_table_foreach (letters_table, (GHFunc) add_char, list_of_letters); /* Log what happened, what was expected, what we got */ gc_log_set_comment(gcomprisBoard, list_of_letters, str); g_free(str); return TRUE; }
/** \brief Save the QTH data to a file. * \param filename The file to save to. * \param qth Pointer to a qth_t data structure from which the data will be read. */ gint qth_data_save(const gchar * filename, qth_t * qth) { gchar *buff; gint ok = 1; qth->data = g_key_file_new(); g_key_file_set_list_separator(qth->data, ';'); /* name */ /* if (qth->name) { */ /* g_key_file_set_string (qth->data, */ /* QTH_CFG_MAIN_SECTION, */ /* QTH_CFG_NAME_KEY, */ /* qth->name); */ /* } */ /* description */ if (qth->desc && (g_utf8_strlen(qth->desc, -1) > 0)) { g_key_file_set_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_DESC_KEY, qth->desc); } /* location */ if (qth->loc && (g_utf8_strlen(qth->loc, -1) > 0)) { g_key_file_set_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_LOC_KEY, qth->loc); } /* latitude */ /* buff = g_strdup_printf ("%.4f", qth->lat); */ buff = g_malloc(10); buff = g_ascii_dtostr(buff, 9, qth->lat); g_key_file_set_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_LAT_KEY, buff); g_free(buff); /* longitude */ /* buff = g_strdup_printf ("%.4f", qth->lon); */ buff = g_malloc(10); buff = g_ascii_dtostr(buff, 9, qth->lon); g_key_file_set_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_LON_KEY, buff); g_free(buff); /* altitude */ g_key_file_set_integer(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_ALT_KEY, qth->alt); /* weather station */ if (qth->wx && (g_utf8_strlen(qth->wx, -1) > 0)) { g_key_file_set_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_WX_KEY, qth->wx); } /* qth type */ /* static, gpsd... */ g_key_file_set_integer(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_TYPE_KEY, qth->type); #if HAS_LIBGPS /* gpsd server */ if (qth->gpsd_server && (g_utf8_strlen(qth->gpsd_server, -1) > 0)) { g_key_file_set_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_GPSD_SERVER_KEY, qth->gpsd_server); } /* gpsd port */ g_key_file_set_integer(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_GPSD_PORT_KEY, qth->gpsd_port); #endif /* saving code */ ok = !(gpredict_save_key_file(qth->data, filename)); return ok; }
static void search_selected(gchar *str) { gchar *euc_str; gint method; glong len; LOG(LOG_DEBUG, "IN : search_selected(%s)", str); if(selection_mode <= SELECTION_DO_NOTHING) { LOG(LOG_DEBUG, "OUT : search_selected() = NOP1"); return; } if(strcmp(previous, str) == 0){ // Do nothing if the word is the save as before. LOG(LOG_DEBUG, "same as before"); ; } else { euc_str = iconv_convert("utf-8", "euc-jp", str); if(validate_euc_str(euc_str) == FALSE) { g_free(euc_str); LOG(LOG_DEBUG, "OUT : search_selected() = INVALID"); return; } remove_space(euc_str); len = g_utf8_strlen(str, -1); if((auto_minchar <= len) && (len <= auto_maxchar)) { gtk_entry_set_text(GTK_ENTRY(word_entry), str); method = ebook_search_method(); if((method == SEARCH_METHOD_INTERNET) || (method == SEARCH_METHOD_MULTI) || (method == SEARCH_METHOD_FULL_TEXT)){ LOG(LOG_DEBUG, "OUT : search_selected() = NOP2"); return; } if(selection_mode <= SELECTION_COPY_ONLY) { LOG(LOG_DEBUG, "OUT : search_selected() = COPY"); return; } clear_message(); clear_search_result(); if(method == SEARCH_METHOD_GREP){ grep_search(euc_str); show_result_tree(); select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); save_word_history(str); } else { ebook_search_auto(euc_str, method); show_result_tree(); if(search_result){ if(selection_mode == SELECTION_POPUP) { show_result_in_popup(); } else { select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); } save_word_history(str); } else { current_in_result = NULL; set_current_result(NULL); if(selection_mode == SELECTION_POPUP) { beep(); } else { if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); push_message(_("No hit.")); } } } sprintf(previous, "%s", str); } else { LOG(LOG_DEBUG, "OUT : search_selected() = LENGTH"); } g_free(euc_str); } LOG(LOG_DEBUG, "OUT : search_selected()"); }
/* set the type of the token returned in string in returned_type */ void get_random_token(int token_type, gint *returned_type, gchar **string, gchar **second_value) { gchar *result = NULL; gchar *second = NULL; gboolean skip; gint max_token; gint j, i, k; gint type; typedef struct { gint bound; gint type; } DATUM ; GList *data= NULL; GList *list; max_token = 0; if (token_type & TYPE_IMAGE){ max_token += NUMBER_OF_IMAGES; DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_IMAGE; data = g_list_append(data, dat); } if (token_type & TYPE_NUMBER) { max_token += g_utf8_strlen (numbers, -1); DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_NUMBER; data = g_list_append(data, dat); } if (token_type & TYPE_UPPERCASE){ max_token += g_utf8_strlen (alphabet_uppercase, -1); DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_UPPERCASE; data = g_list_append(data, dat); } if (token_type & TYPE_LOWERCASE){ max_token += g_utf8_strlen (alphabet_lowercase, -1);; DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_LOWERCASE; data = g_list_append(data, dat); } if (token_type & TYPE_SOUND){ max_token += NUMBER_OF_SOUNDS; DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_SOUND; data = g_list_append(data, dat); } if (token_type & TYPE_ADD){ max_token += (add_levelDescription[gcomprisBoard->level][0]+1)*(add_levelDescription[gcomprisBoard->level][1]+1); DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_ADD; data = g_list_append(data, dat); } if (token_type & TYPE_MINUS){ max_token += (minus_levelDescription[gcomprisBoard->level][0]+1)*(minus_levelDescription[gcomprisBoard->level][1]+1); DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_MINUS; data = g_list_append(data, dat); } if (token_type & TYPE_MULT){ max_token += (mult_levelDescription[gcomprisBoard->level][0]+1)*(mult_levelDescription[gcomprisBoard->level][1]+1); DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_MULT; data = g_list_append(data, dat); } if (token_type & TYPE_DIV){ max_token += (div_levelDescription[gcomprisBoard->level][0]+1)*(div_levelDescription[gcomprisBoard->level][1]+1); DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_DIV; data = g_list_append(data, dat); } if (token_type & TYPE_ENUMERATE){ max_token += NUMBER_OF_ENUMERATES; DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_ENUMERATE; data = g_list_append(data, dat); } if (token_type & TYPE_WORDNUMBER){ max_token += NUMBER_OF_WORDNUMBERS; DATUM *dat = g_malloc0(sizeof(DATUM)); dat->bound = max_token; dat->type = TYPE_WORDNUMBER; data = g_list_append(data, dat); } g_assert(max_token >0); i = g_random_int()%max_token; for (list = data; list != NULL; list = list->next) if ( i < ((DATUM *)list->data)->bound) break; j=-1; do { skip = FALSE; g_free(result); result = NULL; g_free(second); j++; if ((i+j) == max_token) { list = data; } if ((i+j)%max_token == ((DATUM *)list->data)->bound) list = list->next; /* calculate index in right table */ k = (i+j)%max_token - (list->prev ? ((DATUM *)list->prev->data)->bound : 0); type = ((DATUM *)list->data)->type; switch (type) { case TYPE_IMAGE: result= g_strdup(imageList[k]); break; case TYPE_NUMBER: result = g_malloc0(2*sizeof(gunichar)); g_utf8_strncpy(result, g_utf8_offset_to_pointer (numbers,k),1); break; case TYPE_UPPERCASE: result = g_malloc0(2*sizeof(gunichar)); g_utf8_strncpy(result, g_utf8_offset_to_pointer (alphabet_uppercase,k),1); break; case TYPE_LOWERCASE: result = g_malloc0(2*sizeof(gunichar)); g_utf8_strncpy(result, g_utf8_offset_to_pointer (alphabet_lowercase,k),1); break; case TYPE_SOUND: result = g_strdup(soundList[k]); break; case TYPE_ADD: { int i, j; i = k % add_levelDescription[gcomprisBoard->level][0]; j = k / add_levelDescription[gcomprisBoard->level][0]; result = g_strdup_printf("%d %s %d",i,op_add,j); second = g_strdup_printf("%d",i+j);; break; } case TYPE_MINUS: { int i, j; i = k % minus_levelDescription[gcomprisBoard->level][0]; j = k / minus_levelDescription[gcomprisBoard->level][0]; result = g_strdup_printf("%d %s %d",i+j,op_minus,i); second = g_strdup_printf("%d",j);; break; } case TYPE_MULT: { int i, j; i = k % mult_levelDescription[gcomprisBoard->level][0]; j = k / mult_levelDescription[gcomprisBoard->level][0]; result = g_strdup_printf("%d %s %d",i,op_mult,j); second = g_strdup_printf("%d",i*j);; break; } case TYPE_DIV: { int i1, i2; i1 = k % div_levelDescription[gcomprisBoard->level][0]; if (i1==0) skip=TRUE; i2 = k / div_levelDescription[gcomprisBoard->level][0]; result = g_strdup_printf("%d %s %d",i1*i2,op_div,i1); second = g_strdup_printf("%d",i2); break; } case TYPE_ENUMERATE: { result = g_malloc0(2*sizeof(gunichar)); g_utf8_strncpy(result, g_utf8_offset_to_pointer (numbers,k),1); second = g_strdup(enumerateList[k]); break; } case TYPE_WORDNUMBER: { result = g_malloc0(2*sizeof(gunichar)); g_utf8_strncpy(result, g_utf8_offset_to_pointer (numbers,k),1); second = g_strdup(gettext(wordnumberList[k])); break; } default: /* should never append */ g_error("never !"); break; } } while (skip || ((j < max_token ) && (passed_token && result && g_list_find_custom(passed_token, result, (GCompareFunc)strcmp)))); g_assert (j < max_token); passed_token = g_list_append( passed_token, result); *returned_type = type; *string = result; if (second_value) *second_value = second; for (list = data; list != NULL; list=list->next) g_free(list->data); g_list_free(data); }
/** * gail_misc_layout_get_run_attributes: * @attrib_set: The #AtkAttributeSet to add the attribute to * @layout: The PangoLayout from which the attributes will be obtained * @text: The text * @offset: The offset at which the attributes are required * @start_offset: The start offset of the current run * @end_offset: The end offset of the current run * * Adds the attributes for the run starting at offset to the specified * attribute set. * * Returns: A pointer to the #AtkAttributeSet. **/ AtkAttributeSet* gail_misc_layout_get_run_attributes (AtkAttributeSet *attrib_set, PangoLayout *layout, const gchar *text, gint offset, gint *start_offset, gint *end_offset) { PangoAttrIterator *iter; PangoAttrList *attr; PangoAttrString *pango_string; PangoAttrInt *pango_int; PangoAttrColor *pango_color; PangoAttrLanguage *pango_lang; PangoAttrFloat *pango_float; gint index, start_index, end_index; gboolean is_next = TRUE; gchar *value = NULL; glong len; len = g_utf8_strlen (text, -1); /* Grab the attributes of the PangoLayout, if any */ if ((attr = pango_layout_get_attributes (layout)) == NULL) { *start_offset = 0; *end_offset = len; return attrib_set; } iter = pango_attr_list_get_iterator (attr); /* Get invariant range offsets */ /* If offset out of range, set offset in range */ if (offset > len) offset = len; else if (offset < 0) offset = 0; index = g_utf8_offset_to_pointer (text, offset) - text; pango_attr_iterator_range (iter, &start_index, &end_index); while (is_next) { if (index >= start_index && index < end_index) { *start_offset = g_utf8_pointer_to_offset (text, text + start_index); if (end_index == G_MAXINT) /* Last iterator */ end_index = len; *end_offset = g_utf8_pointer_to_offset (text, text + end_index); break; } is_next = pango_attr_iterator_next (iter); pango_attr_iterator_range (iter, &start_index, &end_index); } /* Get attributes */ if ((pango_string = (PangoAttrString*) pango_attr_iterator_get (iter, PANGO_ATTR_FAMILY)) != NULL) { value = g_strdup_printf("%s", pango_string->value); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FAMILY_NAME, value); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_STYLE)) != NULL) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STYLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STYLE, pango_int->value))); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_WEIGHT)) != NULL) { value = g_strdup_printf("%i", pango_int->value); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WEIGHT, value); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_VARIANT)) != NULL) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_VARIANT, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_VARIANT, pango_int->value))); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_STRETCH)) != NULL) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRETCH, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRETCH, pango_int->value))); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_SIZE)) != NULL) { value = g_strdup_printf("%i", pango_int->value / PANGO_SCALE); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SIZE, value); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_UNDERLINE)) != NULL) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_UNDERLINE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_UNDERLINE, pango_int->value))); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_STRIKETHROUGH)) != NULL) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRIKETHROUGH, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRIKETHROUGH, pango_int->value))); } if ((pango_int = (PangoAttrInt*) pango_attr_iterator_get (iter, PANGO_ATTR_RISE)) != NULL) { value = g_strdup_printf("%i", pango_int->value); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RISE, value); } if ((pango_lang = (PangoAttrLanguage*) pango_attr_iterator_get (iter, PANGO_ATTR_LANGUAGE)) != NULL) { value = g_strdup( pango_language_to_string( pango_lang->value)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LANGUAGE, value); } if ((pango_float = (PangoAttrFloat*) pango_attr_iterator_get (iter, PANGO_ATTR_SCALE)) != NULL) { value = g_strdup_printf("%g", pango_float->value); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SCALE, value); } if ((pango_color = (PangoAttrColor*) pango_attr_iterator_get (iter, PANGO_ATTR_FOREGROUND)) != NULL) { value = g_strdup_printf ("%u,%u,%u", pango_color->color.red, pango_color->color.green, pango_color->color.blue); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_COLOR, value); } if ((pango_color = (PangoAttrColor*) pango_attr_iterator_get (iter, PANGO_ATTR_BACKGROUND)) != NULL) { value = g_strdup_printf ("%u,%u,%u", pango_color->color.red, pango_color->color.green, pango_color->color.blue); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_COLOR, value); } pango_attr_iterator_destroy (iter); return attrib_set; }
guint ibus_text_get_length (IBusText *text) { return g_utf8_strlen (text->text, -1); }
static void hangul_engine_shape (PangoEngineShape *engine, PangoFont *font, const char *text, gint length, const PangoAnalysis *analysis, PangoGlyphString *glyphs) { int n_chars, n_glyphs; int i; const char *p, *start; gunichar jamos_static[8]; gint max_jamos = G_N_ELEMENTS (jamos_static); gunichar *jamos = jamos_static; int n_jamos; n_chars = g_utf8_strlen (text, length); n_glyphs = 0; start = p = text; n_jamos = 0; for (i = 0; i < n_chars; i++) { gunichar wc; wc = g_utf8_get_char (p); /* Check syllable boundaries. */ if (n_jamos) { gunichar prev = jamos[n_jamos - 1]; if ((!IS_JAMO (wc) && !IS_S (wc) && !IS_M (wc)) || (!IS_L (prev) && IS_S (wc)) || (IS_T (prev) && IS_L (wc)) || (IS_V (prev) && IS_L (wc)) || (IS_T (prev) && IS_V (wc)) || IS_M (prev)) { /* Draw a syllable with these jamos. */ render_syllable (font, jamos, n_jamos, glyphs, &n_glyphs, start - text); n_jamos = 0; start = p; } } if (n_jamos >= max_jamos - 3) { max_jamos += 8; /* at most 3 for each syllable code (L+V+T) */ if (jamos == jamos_static) { jamos = g_new (gunichar, max_jamos); memcpy (jamos, jamos_static, n_jamos*sizeof(gunichar)); } else jamos = g_renew (gunichar, jamos, max_jamos); } if (!IS_JAMO (wc) && !IS_S (wc) && !IS_M (wc)) { render_basic (font, wc, glyphs, &n_glyphs, start - text); start = g_utf8_next_char (p); } else if (IS_S (wc)) { jamos[n_jamos++] = L_FROM_S (wc); jamos[n_jamos++] = V_FROM_S (wc); if (S_HAS_T (wc)) jamos[n_jamos++] = T_FROM_S (wc); } else if (IS_M (wc) && !n_jamos) { /* Tone mark not following syllable */ render_isolated_tone (font, wc, glyphs, &n_glyphs, start - text); start = g_utf8_next_char (p); } else jamos[n_jamos++] = wc; p = g_utf8_next_char (p); } if (n_jamos != 0) render_syllable (font, jamos, n_jamos, glyphs, &n_glyphs, start - text); if (jamos != jamos_static) g_free(jamos); }
static GooCanvasItem *gletters_create_item(GooCanvasItem *parent) { GooCanvasItem *item; gint i,j,k; guint x; gunichar *lettersItem; gchar *str_p, *letter; if (!letters_table) { letters_table = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, destroy_canvas_item); } /* Beware, since we put the letters in a hash table, we do not allow the same * letter to be displayed two times */ g_warning("dump: %d, %s\n",gcomprisBoard->level,letters_array[gcomprisBoard->level-1]); k = g_utf8_strlen(letters_array[gcomprisBoard->level-1],-1); lettersItem = g_new(gunichar,1); gint attempt=0; do { attempt++; str_p = letters_array[gcomprisBoard->level-1]; i = g_random_int_range(0,k); for(j = 0; j < i; j++) { str_p=g_utf8_next_char(str_p); } *lettersItem = g_utf8_get_char (str_p); } while((attempt<MAX_RAND_ATTEMPTS) && (item_find_by_title(lettersItem)!=NULL)); if (item_find_by_title(lettersItem)!=NULL) { g_free(lettersItem); return NULL; } letter = g_new0(gchar, 6); g_unichar_to_utf8 ( *lettersItem, letter); if (with_sound) { gchar *str2 = NULL; gchar *letter_unichar_name = gc_sound_alphabet(letter); str2 = g_strdup_printf("voices/$LOCALE/alphabet/%s", letter_unichar_name); gc_sound_play_ogg(str2, NULL); g_free(letter_unichar_name); g_free(str2); } item = \ goo_canvas_group_new (parent, NULL); goo_canvas_item_translate(item, 0, -12); x = g_random_int_range( 80, BOARDWIDTH-160); goo_canvas_text_new (item, letter, x, -20, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_huge_bold, "fill_color_rgba", 0x8c8cFFFF, NULL); x -= 2; goo_canvas_text_new (item, letter, x, -22, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_huge_bold, "fill_color_rgba", 0x254c87FF, NULL); g_object_set_data (G_OBJECT(item), "unichar_key", lettersItem); g_object_set_data (G_OBJECT(item), "utf8_key", letter); item_list = g_list_append (item_list, item); ++actors_count; /* Add letter to hash table of all falling letters. */ g_hash_table_insert (letters_table, lettersItem, item); g_free(letter); return (item); }
static gint get_page_count(GtkPrintContext *context, DocInfo *dinfo) { gdouble width, height; gint layout_h; gint i, j, lines_left; gchar *line_buf; if (dinfo == NULL) return -1; width = gtk_print_context_get_width(context); height = gtk_print_context_get_height(context); if (printing_prefs.print_line_numbers) /* remove line number margin space from overall width */ width -= dinfo->max_line_number_margin * dinfo->font_width; pango_layout_set_width(dinfo->layout, width * PANGO_SCALE); /* add test text to get line height */ pango_layout_set_text(dinfo->layout, "Test 1", -1); pango_layout_get_size(dinfo->layout, NULL, &layout_h); if (layout_h <= 0) { geany_debug("Invalid layout_h (%d). Falling back to default height (%d)", layout_h, 100 * PANGO_SCALE); layout_h = 100 * PANGO_SCALE; } dinfo->line_height = (gdouble)layout_h / PANGO_SCALE; dinfo->lines_per_page = ceil((height - dinfo->line_height) / dinfo->line_height); #ifdef GEANY_PRINT_DEBUG geany_debug("max lines_per_page: %d", dinfo->lines_per_page); #endif if (printing_prefs.print_page_numbers) dinfo->lines_per_page -= 2; if (printing_prefs.print_page_header) dinfo->lines_per_page -= 3; lines_left = dinfo->lines_per_page; i = 0; for (j = 0; j < dinfo->lines; j++) { gint lines = 1; gint line_width; line_buf = sci_get_line(dinfo->doc->editor->sci, j); line_width = (g_utf8_strlen(line_buf, -1) + 1) * dinfo->font_width; if (line_width > width) lines = ceil(line_width / width); #ifdef GEANY_PRINT_DEBUG if (lines != 1) geany_debug("%d %d", j+1, lines); #endif while (lines_left < lines) { lines -= lines_left; lines_left = dinfo->lines_per_page; i++; } lines_left -= lines; g_free(line_buf); } return i + 1; }
int main( int argc, char** argv ) { int status = EXIT_SUCCESS; GOptionContext *context; GError *error = NULL; NAObjectAction *action; GSList *msg = NULL; GSList *im; gchar *help; gint errors; #if !GLIB_CHECK_VERSION( 2,36, 0 ) g_type_init(); #endif setlocale( LC_ALL, "" ); console_init_log_handler(); context = init_options(); if( argc == 1 ){ g_set_prgname( argv[0] ); help = g_option_context_get_help( context, FALSE, NULL ); g_print( "\n%s", help ); g_free( help ); exit( status ); } if( !g_option_context_parse( context, &argc, &argv, &error )){ g_printerr( _( "Syntax error: %s\n" ), error->message ); g_error_free (error); exit_with_usage(); } if( version ){ na_core_utils_print_version(); exit( status ); } errors = 0; if( !label || !g_utf8_strlen( label, -1 )){ g_printerr( _( "Error: an action label is mandatory.\n" )); errors += 1; } if( enabled && disabled ){ g_printerr( CANNOT_BOTH, "--enabled", "--disabled" ); errors += 1; } else if( !disabled ){ enabled = TRUE; } if( target_selection && nocontext ){ g_printerr( CANNOT_BOTH, "--context", "--nocontext" ); errors += 1; } else if( !nocontext ){ target_selection = TRUE; } if( target_location && nolocation ){ g_printerr( CANNOT_BOTH, "--location", "--nolocation" ); errors += 1; } if( target_toolbar && notoolbar ){ g_printerr( CANNOT_BOTH, "--toolbar", "--notoolbar" ); errors += 1; } if( matchcase && nocase ){ g_printerr( CANNOT_BOTH, "--match-case", "--nocase" ); errors += 1; } else if( !nocase ){ matchcase = TRUE; } if( accept_multiple && strlen( selection_count )){ g_printerr( CANNOT_BOTH, "--accept-multiple", "--selection-count" ); errors += 1; } if( onlyshow_array && notshow_array ){ g_printerr( CANNOT_BOTH, "--only-show-in", "--not-show-in" ); errors += 1; } if( output_stdout && output_desktop ){ g_printerr( _( "Error: only one output option may be specified.\n" )); errors += 1; } if( errors ){ exit_with_usage(); } action = get_action_from_cmdline(); if( output_desktop ){ output_to_desktop( action, &msg ); } else { output_to_stdout( action, &msg ); } if( msg ){ for( im = msg ; im ; im = im->next ){ g_printerr( "%s\n", ( gchar * ) im->data ); } na_core_utils_slist_free( msg ); status = EXIT_FAILURE; } g_object_unref( action ); g_option_context_free( context ); exit( status ); }
static void ev_document_setup_cache (EvDocument *document) { EvDocumentPrivate *priv = document->priv; gint i; /* Cache some info about the document to avoid * going to the backends since it requires locks */ priv->n_pages = _ev_document_get_n_pages (document); for (i = 0; i < priv->n_pages; i++) { EvPage *page = ev_document_get_page (document, i); gdouble page_width = 0; gdouble page_height = 0; EvPageSize *page_size; gchar *page_label; _ev_document_get_page_size (document, page, &page_width, &page_height); if (i == 0) { priv->uniform_width = page_width; priv->uniform_height = page_height; priv->max_width = priv->uniform_width; priv->max_height = priv->uniform_height; priv->min_width = priv->uniform_width; priv->min_height = priv->uniform_height; } else if (priv->uniform && (priv->uniform_width != page_width || priv->uniform_height != page_height)) { /* It's a different page size. Backfill the array. */ int j; priv->page_sizes = g_new0 (EvPageSize, priv->n_pages); for (j = 0; j < i; j++) { page_size = &(priv->page_sizes[j]); page_size->width = priv->uniform_width; page_size->height = priv->uniform_height; } priv->uniform = FALSE; } if (!priv->uniform) { page_size = &(priv->page_sizes[i]); page_size->width = page_width; page_size->height = page_height; if (page_width > priv->max_width) priv->max_width = page_width; if (page_width < priv->min_width) priv->min_width = page_width; if (page_height > priv->max_height) priv->max_height = page_height; if (page_height < priv->min_height) priv->min_height = page_height; } page_label = _ev_document_get_page_label (document, page); if (page_label) { if (!priv->page_labels) priv->page_labels = g_new0 (gchar *, priv->n_pages); priv->page_labels[i] = page_label; priv->max_label = MAX (priv->max_label, g_utf8_strlen (page_label, 256)); } g_object_unref (page); } }
/* * allocate a new action, and fill it with values read from command-line */ static NAObjectAction * get_action_from_cmdline( void ) { NAObjectAction *action; NAObjectProfile *profile; int i; GSList *basenames; GSList *mimetypes; GSList *schemes; GSList *folders; gboolean toolbar_same_label; gchar *msg; GSList *only_show_in; GSList *not_show_in; GSList *capabilities; action = na_object_action_new_with_defaults(); profile = NA_OBJECT_PROFILE(( GList * ) na_object_get_items( action )->data ); na_object_set_label( action, label ); if( tooltip && g_utf8_strlen( tooltip, -1 )){ na_object_set_tooltip( action, tooltip ); } if( icon && g_utf8_strlen( icon, -1 )){ na_object_set_icon( action, icon ); } na_object_set_enabled( action, enabled ); na_object_set_target_selection( action, target_selection ); na_object_set_target_location( action, target_location ); na_object_set_target_toolbar( action, target_toolbar ); toolbar_same_label = FALSE; if( !label_toolbar || !g_utf8_strlen( label_toolbar, -1 )){ label_toolbar = g_strdup( label ); toolbar_same_label = TRUE; } na_object_set_toolbar_same_label( action, toolbar_same_label ); na_object_set_toolbar_label( action, label_toolbar ); na_object_set_path( profile, command ); na_object_set_parameters( profile, parameters ); i = 0; basenames = NULL; while( basenames_array != NULL && basenames_array[i] != NULL ){ basenames = g_slist_append( basenames, g_strdup( basenames_array[i] )); i++; } if( basenames && g_slist_length( basenames )){ na_object_set_basenames( profile, basenames ); na_core_utils_slist_free( basenames ); } na_object_set_matchcase( profile, matchcase ); mimetypes = NULL; if( isfile ){ msg = g_strdup_printf( DEPRECATED, "accept-files", "mimetype" ); g_warning( "%s", msg ); g_free( msg ); } if( isdir ){ msg = g_strdup_printf( DEPRECATED, "accept-dirs", "mimetype" ); g_warning( "%s", msg ); g_free( msg ); } if( isfile && !isdir ){ mimetypes = g_slist_prepend( mimetypes, g_strdup( "all/allfiles" )); } else if( isdir && !isfile ){ mimetypes = g_slist_prepend( mimetypes, g_strdup( "inode/directory" )); } i = 0; while( mimetypes_array != NULL && mimetypes_array[i] != NULL ){ mimetypes = g_slist_append( mimetypes, g_strdup( mimetypes_array[i] )); i++; } if( mimetypes && g_slist_length( mimetypes )){ na_object_set_mimetypes( profile, mimetypes ); na_core_utils_slist_free( mimetypes ); } if( accept_multiple ){ msg = g_strdup_printf( DEPRECATED, "accept-multiple", "selection-count" ); g_warning( "%s", msg ); g_free( msg ); selection_count = g_strdup( ">0" ); } if( strlen( selection_count )){ na_object_set_selection_count( profile, selection_count ); } i = 0; schemes = NULL; while( schemes_array != NULL && schemes_array[i] != NULL ){ schemes = g_slist_append( schemes, g_strdup( schemes_array[i] )); i++; } if( schemes && g_slist_length( schemes )){ na_object_set_schemes( profile, schemes ); na_core_utils_slist_free( schemes ); } i = 0; folders = NULL; while( folders_array != NULL && folders_array[i] != NULL ){ folders = g_slist_append( folders, g_strdup( folders_array[i] )); i++; } if( folders && g_slist_length( folders )){ na_object_set_folders( profile, folders ); na_core_utils_slist_free( folders ); } if( onlyshow_array ){ only_show_in = NULL; for( i = 0 ; onlyshow_array[i] && strlen( onlyshow_array[i] ) ; ++i ){ only_show_in = g_slist_append( only_show_in, g_strdup( onlyshow_array[i] )); } if( only_show_in && g_slist_length( only_show_in )){ na_object_set_only_show_in( profile, only_show_in ); na_core_utils_slist_free( only_show_in ); } } if( notshow_array ){ not_show_in = NULL; for( i = 0 ; notshow_array[i] && strlen( notshow_array[i] ) ; ++i ){ not_show_in = g_slist_append( not_show_in, g_strdup( notshow_array[i] )); } if( not_show_in && g_slist_length( not_show_in )){ na_object_set_not_show_in( profile, not_show_in ); na_core_utils_slist_free( not_show_in ); } } if( try_exec && strlen( try_exec )){ na_object_set_try_exec( profile, try_exec ); } if( show_registered && strlen( show_registered )){ na_object_set_show_if_registered( profile, show_registered ); } if( show_true && strlen( show_true )){ na_object_set_show_if_true( profile, show_true ); } if( show_running && strlen( show_running )){ na_object_set_show_if_running( profile, show_running ); } if( capability_array ){ capabilities = NULL; for( i = 0 ; capability_array[i] && strlen( capability_array[i] ) ; ++i ){ const gchar *cap = ( const gchar * ) capability_array[i]; /* 'Owner', 'Readable', 'Writable', 'Executable' and 'Local' */ if( strcmp( cap, "Owner" ) && strcmp( cap, "Readable" ) && strcmp( cap, "Writable" ) && strcmp( cap, "Executable" ) && strcmp( cap, "Local" )){ g_warning( "%s: unknown capability", cap ); } else { capabilities = g_slist_append( capabilities, g_strdup( capability_array[i] )); } } if( capabilities && g_slist_length( capabilities )){ na_object_set_capabilities( profile, capabilities ); na_core_utils_slist_free( capabilities ); } } return( action ); }
static void _xim_preedit_callback_draw (XIMS xims, X11IC *x11ic, const gchar *preedit_string, IBusAttrList *attr_list) { IMPreeditCBStruct pcb; XIMText text; XTextProperty tp; static XIMFeedback *feedback; static gint feedback_len = 0; guint j, i, len; if (preedit_string == NULL) return; len = g_utf8_strlen (preedit_string, -1); if (len + 1 > feedback_len) { feedback_len = (len + 1 + 63) & ~63; if (feedback) { feedback = g_renew (XIMFeedback, feedback, feedback_len); } else { feedback = g_new (XIMFeedback, feedback_len); } } for (i = 0; i < len; i++) { feedback[i] = 0; } if (attr_list != NULL) { for (i = 0;; i++) { XIMFeedback attr = 0; IBusAttribute *ibus_attr = ibus_attr_list_get (attr_list, i); if (ibus_attr == NULL) { break; } switch (ibus_attr->type) { case IBUS_ATTR_TYPE_UNDERLINE: if (ibus_attr->value == IBUS_ATTR_UNDERLINE_SINGLE) { attr = XIMUnderline; } break; case IBUS_ATTR_TYPE_BACKGROUND: { if (ibus_attr->value != 0xffffff) { attr = XIMReverse; } break; } default: continue; } for (j = ibus_attr->start_index; j < ibus_attr->end_index; j++) { feedback[j] |= attr; } } } for (i = 0; i < len; i++) { if (feedback[i] == 0) { feedback[i] = XIMUnderline; } } feedback[len] = 0; pcb.major_code = XIM_PREEDIT_DRAW; pcb.connect_id = x11ic->connect_id; pcb.icid = x11ic->icid; pcb.todo.draw.caret = len; pcb.todo.draw.chg_first = 0; pcb.todo.draw.chg_length = x11ic->onspot_preedit_length; pcb.todo.draw.text = &text; text.feedback = feedback; if (len > 0) { Xutf8TextListToTextProperty (GDK_DISPLAY (), (char **)&preedit_string, 1, XCompoundTextStyle, &tp); text.encoding_is_wchar = 0; text.length = strlen ((char*)tp.value); text.string.multi_byte = (char*)tp.value; IMCallCallback (xims, (XPointer) & pcb); XFree (tp.value); } else { text.encoding_is_wchar = 0; text.length = 0; text.string.multi_byte = ""; IMCallCallback (xims, (XPointer) & pcb); len = 0; } x11ic->onspot_preedit_length = len; }
static void _eventd_events_parse_group(EventdEvents *self, const gchar *group, GKeyFile *config_file) { gchar *name = NULL; const gchar *id, *s; id = group + strlen("Event "); if ( ( s = g_utf8_strchr(id, -1, ' ') ) != NULL ) { const gchar *e = s; s = g_utf8_next_char(s); gunichar c = g_utf8_get_char(s); if ( c == '*' ) { c = g_utf8_get_char(g_utf8_next_char(s)); if ( ( c != ' ' ) && ( c != '\0' ) ) { g_warning("Wrong event specification '%s': * should be alone", id); return; } name = g_strndup(id, e - id); } else if ( ( s = g_utf8_strchr(g_utf8_next_char(s), -1, ' ') ) != NULL ) name = g_strndup(id, s - id); else name = g_strdup(id); } else name = g_strdup(id); g_strstrip(name); gboolean disable = FALSE; if ( ( evhelpers_config_key_file_get_boolean(config_file, group, "Disable", &disable) < 0 ) || disable ) goto fail; gchar **actions = NULL; if ( evhelpers_config_key_file_get_string_list(config_file, group, "Actions", &actions, NULL) < 0 ) goto fail; eventd_debug("Parsing event: %s", id); EventdEventsEvent *event; event = g_new0(EventdEventsEvent, 1); if ( actions != NULL ) { gchar **action; for ( action = actions ; *action != NULL ; ++action ) event->actions = g_list_prepend(event->actions, *action); g_free(actions); } gchar **if_data; gchar **if_data_matches; gchar **if_data_regexes; gchar **flags; gsize length; if ( evhelpers_config_key_file_get_string_list(config_file, group, "IfData", &if_data, NULL) == 0 ) event->if_data = if_data; if ( evhelpers_config_key_file_get_string_list(config_file, group, "IfDataMatches", &if_data_matches, &length) == 0 ) { gchar **if_data_match; EventdEventsEventDataMatch *match; gchar *tmp, *data, *key = NULL, *operator, *value_; gint accepted[2]; GVariant *value; GError *error = NULL; event->if_data_matches = g_new0(EventdEventsEventDataMatch, length + 1); match = event->if_data_matches; for ( if_data_match = if_data_matches ; *if_data_match != NULL ; ++if_data_match ) { data = *if_data_match; tmp = g_utf8_strchr(data, -1, ','); if ( tmp == NULL ) { g_warning("Data matches must be of the form 'data-name,operator,value'"); g_free(data); continue; } operator = g_utf8_next_char(tmp); *tmp = '\0'; tmp = g_utf8_strchr(data, -1, '['); if ( tmp != NULL ) { key = g_utf8_next_char(tmp); *tmp = '\0'; tmp = g_utf8_strchr(key, -1, ']'); if ( ( tmp == NULL ) || ( g_utf8_get_char(g_utf8_next_char(tmp)) != '\0' ) ) { g_warning("Data matches must be of the form 'data-name[key],operator,value'"); g_free(data); continue; } *tmp = '\0'; } tmp = g_utf8_strchr(operator, -1, ','); if ( tmp == NULL ) { g_warning("Data matches must be of the form 'data-name,operator,value'"); g_free(data); continue; } value_ = g_utf8_next_char(tmp); *tmp = '\0'; gsize l = g_utf8_strlen(operator, -1); if ( ( l > 2 ) || ( l < 1 ) ) { g_warning("Unsupported operator: %s", operator); g_free(data); continue; } accepted[0] = -2; switch ( g_utf8_get_char(g_utf8_next_char(operator)) ) { case '=': accepted[1] = 0; switch ( g_utf8_get_char(operator) ) { case '<': accepted[0] = -1; break; case '>': accepted[0] = 1; break; case '=': accepted[0] = 0; break; case '!': accepted[0] = -1; accepted[1] = 1; break; } break; case '\0': switch ( g_utf8_get_char(operator) ) { case '<': accepted[0] = accepted[1] = -1; break; case '>': accepted[0] = accepted[1] = 1; break; } } if ( accepted[0] == -2 ) { g_warning("Unsupported operator: %s", operator); g_free(data); continue; } value = g_variant_parse(NULL, value_, NULL, NULL, &error); if ( value == NULL ) { g_warning("Could not parse variant '%s': %s", value_, error->message); g_clear_error(&error); g_free(data); continue; } match->data = data; match->key = key; match->accepted[0] = accepted[0]; match->accepted[1] = accepted[1]; match->value = value; ++match; } match->data = NULL; g_free(if_data_matches); } if ( evhelpers_config_key_file_get_string_list(config_file, group, "IfDataRegex", &if_data_regexes, &length) == 0 ) { gchar **if_data_regex; EventdEventsEventDataRegex *match; gchar *data, *regex_; GError *error = NULL; GRegex *regex; event->if_data_regexes = g_new0(EventdEventsEventDataRegex, length + 1); match = event->if_data_regexes; for ( if_data_regex = if_data_regexes ; *if_data_regex != NULL ; ++if_data_regex ) { data = *if_data_regex; regex_ = g_utf8_strchr(data, -1, ','); if ( regex_ == NULL ) { g_warning("Data matches must be of the form 'data-name,regex'"); g_free(data); continue; } *regex_ = '\0'; ++regex_; regex = g_regex_new(regex_, G_REGEX_OPTIMIZE, 0, &error); if ( regex == NULL ) { g_warning("Could not compile regex '%s': %s", regex_, error->message); g_clear_error(&error); g_free(data); continue; } match->data = data; match->regex = regex; ++match; } match->data = NULL; g_free(if_data_regexes); } if ( evhelpers_config_key_file_get_string_list(config_file, group, "OnlyIfFlags", &flags, &length) == 0 ) event->flags_whitelist = _eventd_events_parse_event_flags(flags, length); if ( evhelpers_config_key_file_get_string_list(config_file, group, "NotIfFlags", &flags, &length) == 0 ) event->flags_blacklist = _eventd_events_parse_event_flags(flags, length); gint64 default_importance, importance; if ( ( event->if_data != NULL ) || ( event->if_data_matches != NULL ) || ( event->if_data_regexes != NULL ) || ( event->flags_whitelist != NULL ) || ( event->flags_blacklist != NULL ) ) default_importance = 0; else default_importance = G_MAXINT64; if ( evhelpers_config_key_file_get_int_with_default(config_file, group, "Importance", default_importance, &importance) >= 0 ) event->importance = importance; GList *list = NULL; gchar *old_key = NULL; g_hash_table_lookup_extended(self->events, name, (gpointer *)&old_key, (gpointer *)&list); g_hash_table_steal(self->events, name); g_free(old_key); list = g_list_insert_sorted(list, event, _eventd_events_compare_event); g_hash_table_insert(self->events, name, list); name = NULL; fail: g_free(name); }
static void _lib_recentcollection_updated(gpointer instance, gpointer user_data) { dt_lib_module_t *self =(dt_lib_module_t *)user_data; dt_lib_recentcollect_t *d = (dt_lib_recentcollect_t *)self->data; // serialize, check for recently used char confname[200]; const int bufsize = 4096; char buf[bufsize]; if(dt_collection_serialize(buf, bufsize)) return; // is the current position, i.e. the one to be stored with the old collection (pos0, pos1-to-be) uint32_t curr_pos = 0; if(d->inited) { curr_pos = dt_view_lighttable_get_position(darktable.view_manager); dt_conf_set_int("plugins/lighttable/recentcollect/pos0", curr_pos); } else { curr_pos = dt_conf_get_int("plugins/lighttable/recentcollect/pos0"); d->inited = 1; } uint32_t new_pos = 0; int n = -1; for(int k=0; k<CLAMPS(dt_conf_get_int("plugins/lighttable/recentcollect/num_items"), 0, NUM_LINES); k++) { // is it already in the current list? snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k); gchar *line = dt_conf_get_string(confname); if(!line) continue; if(!strcmp(line, buf)) { snprintf(confname, 200, "plugins/lighttable/recentcollect/pos%1d", k); new_pos = dt_conf_get_int(confname); n = k; break; } g_free(line); } if(n < 0) { const int num_items = CLAMPS(dt_conf_get_int("plugins/lighttable/recentcollect/num_items"), 0, NUM_LINES); if(num_items < NUM_LINES) { // new, unused entry n = num_items; dt_conf_set_int("plugins/lighttable/recentcollect/num_items", num_items + 1); } else { // kill least recently used entry: n = num_items - 1; } } if(n >= 0 && n < NUM_LINES) { // sort n to the top for(int k=n; k>0; k--) { snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k-1); gchar *line1 = dt_conf_get_string(confname); snprintf(confname, 200, "plugins/lighttable/recentcollect/pos%1d", k-1); uint32_t pos1 = dt_conf_get_int(confname); if(line1 && line1[0] != '\0') { snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k); dt_conf_set_string(confname, line1); snprintf(confname, 200, "plugins/lighttable/recentcollect/pos%1d", k); dt_conf_set_int(confname, pos1); } g_free(line1); } dt_conf_set_string("plugins/lighttable/recentcollect/line0", buf); dt_conf_set_int("plugins/lighttable/recentcollect/pos0", new_pos); } // update button descriptions: for(int k=0; k<NUM_LINES; k++) { char str[200] = {0}; char str_cut[200] = {0}; char str_pretty[200] = {0}; snprintf(confname, 200, "plugins/lighttable/recentcollect/line%1d", k); gchar *buf = dt_conf_get_string(confname); if(buf && buf[0] != '\0') { pretty_print(buf, str); g_free(buf); } g_object_set(G_OBJECT(d->item[k].button), "tooltip-text", str, (char *)NULL); const int cut = 45; if (g_utf8_strlen(str, -1) > cut) { g_utf8_strncpy(str_cut, str, cut); snprintf(str_pretty, 200, "%s...", str_cut); gtk_button_set_label(GTK_BUTTON(d->item[k].button), str_pretty); } else { gtk_button_set_label(GTK_BUTTON(d->item[k].button), str); } gtk_widget_set_no_show_all(d->item[k].button, TRUE); gtk_widget_set_visible(d->item[k].button, FALSE); } for(int k=0; k<CLAMPS(dt_conf_get_int("plugins/lighttable/recentcollect/num_items"), 0, NUM_LINES); k++) { gtk_widget_set_no_show_all(d->item[k].button, FALSE); gtk_widget_set_visible(d->item[k].button, TRUE); } dt_view_lighttable_set_position(darktable.view_manager, new_pos); }
static void meh_screen_popup_favorite_toggle(App* app, Screen* screen) { g_assert(app != NULL); g_assert(screen != NULL); PopupData* data = meh_screen_popup_get_data(screen); ExecutableListData* exec_list_data = meh_exec_list_get_data(data->src_screen); /* updates the value of the executable */ gboolean new_value = data->executable->favorite == 1 ? FALSE : TRUE; if (meh_db_set_executable_favorite(app->db, data->executable, new_value)) { data->executable->favorite = new_value; } /* re-position the executable in the executables list if necessary */ if (g_queue_get_length(exec_list_data->executables) > 1) { int prev_selected = exec_list_data->selected_executable; unsigned int i = 0; /* retrieves the one which will move in the list */ Executable* to_move = g_queue_pop_nth(exec_list_data->executables, exec_list_data->selected_executable); /* find the good position for the moved executable */ for (i = 0; i < g_queue_get_length(exec_list_data->executables); i++) { gboolean exit = FALSE; Executable* ex = g_queue_peek_nth(exec_list_data->executables, i); /* if favorite, ensure to stay in the favorite zone */ if (new_value == TRUE) { if (ex->favorite == FALSE) { exit = TRUE; } } gchar* first = g_utf8_strup(ex->display_name, g_utf8_strlen(ex->display_name, -1)); gchar* second = g_utf8_strup(data->executable->display_name, g_utf8_strlen(ex->display_name, -1)); if (g_utf8_collate(first, second) > 0) { if (new_value == TRUE && ex->favorite == TRUE) { exit = TRUE; } else if (new_value == FALSE && ex->favorite == FALSE) { exit = TRUE; } } g_free(first); g_free(second); if (exit) { break; } } GList* after = g_queue_peek_nth_link(exec_list_data->executables, i); /* re-add it to the good position */ g_queue_insert_before(exec_list_data->executables, after, to_move); /* notify the screen of the new selected executable */ exec_list_data->selected_executable = i; /* redraw the executables list texts */ meh_exec_selection_refresh_executables_widgets(app, data->src_screen); /* move and redraw the selection */ meh_exec_list_after_cursor_move(app, data->src_screen, prev_selected); } /* finally close the popup */ meh_screen_popup_close(app, screen); }
static PropertyPage * create_property_page (NemoFileInfo *fileinfo) { PropertyPage *page; GError *error; ShareInfo *share_info; char *share_name; gboolean free_share_name; const char *comment; char *apply_button_label; page = g_new0 (PropertyPage, 1); page->path = get_fullpath_from_fileinfo(fileinfo); page->fileinfo = g_object_ref (fileinfo); error = NULL; if (!shares_get_share_info_for_path (page->path, &share_info, &error)) { /* We'll assume that there is no share for that path, but we'll still * bring up an error dialog. */ GtkWidget *message; message = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("There was an error while getting the sharing information")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s", error->message); gtk_widget_show (message); share_info = NULL; g_error_free (error); error = NULL; } page->xml = gtk_builder_new (); gtk_builder_set_translation_domain (page->xml, "nemo-share"); g_assert (gtk_builder_add_from_file (page->xml, INTERFACES_DIR"/share-dialog.ui", &error)); page->main = GTK_WIDGET (gtk_builder_get_object (page->xml, "vbox1")); g_assert (page->main != NULL); g_object_set_data_full (G_OBJECT (page->main), "PropertyPage", page, free_property_page_cb); page->checkbutton_share_folder = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_folder")); page->hbox_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_comment")); page->hbox_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"hbox_share_name")); page->checkbutton_share_rw_ro = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_rw_ro")); page->checkbutton_share_guest_ok = GTK_WIDGET (gtk_builder_get_object (page->xml,"checkbutton_share_guest_ok")); page->entry_share_name = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_name")); page->entry_share_comment = GTK_WIDGET (gtk_builder_get_object (page->xml,"entry_share_comment")); page->label_status = GTK_WIDGET (gtk_builder_get_object (page->xml,"label_status")); page->button_cancel = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_cancel")); page->button_apply = GTK_WIDGET (gtk_builder_get_object (page->xml,"button_apply")); /* Sanity check so that we don't screw up the Glade file */ g_assert (page->checkbutton_share_folder != NULL && page->hbox_share_comment != NULL && page->hbox_share_name != NULL && page->checkbutton_share_rw_ro != NULL && page->checkbutton_share_guest_ok != NULL && page->entry_share_name != NULL && page->entry_share_comment != NULL && page->label_status != NULL && page->button_cancel != NULL && page->button_apply != NULL); if (share_info) { page->was_initially_shared = TRUE; page->was_writable = share_info->is_writable; } /* Share name */ if (share_info) { share_name = share_info->share_name; free_share_name = FALSE; } else { share_name = g_filename_display_basename (page->path); free_share_name = TRUE; } gtk_entry_set_text (GTK_ENTRY (page->entry_share_name), share_name); if (free_share_name) g_free (share_name); /* Comment */ if (share_info == NULL || share_info->comment == NULL) comment = ""; else comment = share_info->comment; gtk_entry_set_text (GTK_ENTRY (page->entry_share_comment), comment); /* Share toggle */ if (share_info) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_folder), TRUE); else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_folder), FALSE); } /* Share name */ if (g_utf8_strlen(gtk_entry_get_text (GTK_ENTRY (page->entry_share_name)), -1) > 12) property_page_set_warning (page); /* Permissions */ if (share_info != NULL && share_info->is_writable) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), TRUE); else gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro), FALSE); /* Guest access */ if (share_info != NULL && share_info->guest_ok) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), TRUE); else gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_guest_ok), FALSE); /* Apply button */ if (share_info) apply_button_label = _("Modify _Share"); else apply_button_label = _("Create _Share"); gtk_button_set_label (GTK_BUTTON (page->button_apply), apply_button_label); gtk_button_set_use_underline (GTK_BUTTON (page->button_apply), TRUE); gtk_button_set_image (GTK_BUTTON (page->button_apply), gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON)); gtk_widget_set_sensitive (page->button_apply, FALSE); /* Sensitivity */ property_page_check_sensitivity (page); /* Signal handlers */ g_signal_connect (page->checkbutton_share_folder, "toggled", G_CALLBACK (on_checkbutton_share_folder_toggled), page); g_signal_connect (page->checkbutton_share_rw_ro, "toggled", G_CALLBACK (on_checkbutton_rw_ro_toggled), page); g_signal_connect (page->checkbutton_share_guest_ok, "toggled", G_CALLBACK (on_checkbutton_guest_ok_toggled), page); g_signal_connect (page->entry_share_name, "changed", G_CALLBACK (modify_share_name_text_entry), page); g_signal_connect (page->entry_share_comment, "changed", G_CALLBACK (modify_share_comment_text_entry), page); g_signal_connect (page->button_apply, "clicked", G_CALLBACK (button_apply_clicked_cb), page); if (share_info != NULL) shares_free_share_info (share_info); return page; }
static void rm_fmt_progress_format_text(RmSession *session, RmFmtHandlerProgress *self, int max_len, FILE *out) { char num_buf[32] = {0}; char preproc_buf[128] = {0}; memset(num_buf, 0, sizeof(num_buf)); memset(preproc_buf, 0, sizeof(preproc_buf)); switch(self->last_state) { case RM_PROGRESS_STATE_TRAVERSE: self->percent = 2.0; self->text_len = g_snprintf( self->text_buf, sizeof(self->text_buf), "%s (%s%d%s %s / %s%d%s + %s%d%s %s)", _("Traversing"), MAYBE_GREEN(out, session), session->total_files, MAYBE_RESET(out, session), _("usable files"), MAYBE_RED(out, session), session->ignored_files, MAYBE_RESET(out, session), MAYBE_RED(out, session), session->ignored_folders, MAYBE_RESET(out, session), _("ignored files / folders")); break; case RM_PROGRESS_STATE_PREPROCESS: self->percent = 2.0; rm_fmt_progress_format_preprocess(session, preproc_buf, sizeof(preproc_buf), out); self->text_len = g_snprintf( self->text_buf, sizeof(self->text_buf), "%s (%s / %s %s%" LLU "%s %s)", _("Preprocessing"), preproc_buf, _("found"), MAYBE_RED(out, session), session->other_lint_cnt, MAYBE_RESET(out, session), _("other lint")); break; case RM_PROGRESS_STATE_SHREDDER: self->percent = 1.0 - ((gdouble)session->shred_bytes_remaining / (gdouble)session->shred_bytes_after_preprocess); rm_util_size_to_human_readable(session->shred_bytes_remaining, num_buf, sizeof(num_buf)); self->text_len = g_snprintf( self->text_buf, sizeof(self->text_buf), "%s (%s%" LLU "%s %s %s%" LLU "%s %s; %s%s%s %s %s%" LLU "%s %s)", _("Matching"), MAYBE_RED(out, session), session->dup_counter, MAYBE_RESET(out, session), _("dupes of"), MAYBE_YELLOW(out, session), session->dup_group_counter, MAYBE_RESET(out, session), _("originals"), MAYBE_GREEN(out, session), num_buf, MAYBE_RESET(out, session), _("to scan in"), MAYBE_GREEN(out, session), session->shred_files_remaining, MAYBE_RESET(out, session), _("files")); break; case RM_PROGRESS_STATE_MERGE: self->percent = 1.0; self->text_len = g_snprintf(self->text_buf, sizeof(self->text_buf), _("Merging files into directories (stand by...)")); break; case RM_PROGRESS_STATE_INIT: case RM_PROGRESS_STATE_PRE_SHUTDOWN: case RM_PROGRESS_STATE_SUMMARY: default: self->percent = 0; memset(self->text_buf, 0, sizeof(self->text_buf)); break; } /* Support unicode messages - tranlsated text might contain some. */ self->text_len = g_utf8_strlen(self->text_buf, self->text_len); /* Get rid of colors */ int text_iter = 0; for(char *iter = &self->text_buf[0]; *iter; iter++) { if(*iter == '\x1b') { char *jump = strchr(iter, 'm'); if(jump != NULL) { self->text_len -= jump - iter + 1; iter = jump; continue; } } if(text_iter >= max_len) { *iter = 0; self->text_len = text_iter; break; } text_iter++; } }
static gboolean backward_lines_match (const GtkTextIter *start, const gchar **lines, gboolean visible_only, gboolean slice, GtkTextIter *match_start, GtkTextIter *match_end) { GtkTextIter line, next; gchar *line_text; const gchar *found; gint offset; if (*lines == NULL || **lines == '\0') { if (match_start) *match_start = *start; if (match_end) *match_end = *start; return TRUE; } line = next = *start; if (gtk_text_iter_get_line_offset (&next) == 0) { if (!gtk_text_iter_backward_line (&next)) return FALSE; } else gtk_text_iter_set_line_offset (&next, 0); if (slice) { if (visible_only) line_text = gtk_text_iter_get_visible_slice (&next, &line); else line_text = gtk_text_iter_get_slice (&next, &line); } else { if (visible_only) line_text = gtk_text_iter_get_visible_text (&next, &line); else line_text = gtk_text_iter_get_text (&next, &line); } if (match_start) /* if this is the first line we're matching */ { found = g_utf8_strrcasestr (line_text, *lines); } else { /* If it's not the first line, we have to match from the * start of the line. */ if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text), strlen (*lines))) found = line_text; else found = NULL; } if (found == NULL) { g_free (line_text); return FALSE; } /* Get offset to start of search string */ offset = g_utf8_strlen (line_text, found - line_text); forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE); /* If match start needs to be returned, set it to the * start of the search string. */ if (match_start) { *match_start = next; } /* Go to end of search string */ forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE); g_free (line_text); ++lines; if (match_end) *match_end = next; /* try to match the rest of the lines forward, passing NULL * for match_start so lines_match will try to match the entire * line */ return lines_match (&next, lines, visible_only, slice, NULL, match_end); }
static GtkWidget * vcombo_create_list (SheetObject *so, GtkTreePath **clip, GtkTreePath **select, gboolean *make_buttons) { GnmValidationCombo *vcombo = GNM_VALIDATION_COMBO (so); unsigned i; UniqueCollection uc; GnmEvalPos ep; GtkTreeIter iter; GtkWidget *list; GPtrArray *sorted; GtkListStore *model; GnmValue *v; GnmValue const *cur_val; GnmValidation const *val = vcombo->validation; SheetView const *sv = vcombo->parent.sv; g_return_val_if_fail (val != NULL, NULL); g_return_val_if_fail (val->type == GNM_VALIDATION_TYPE_IN_LIST, NULL); g_return_val_if_fail (val->deps[0].texpr != NULL, NULL); g_return_val_if_fail (sv != NULL, NULL); eval_pos_init_editpos (&ep, sv); v = gnm_expr_top_eval (val->deps[0].texpr, &ep, GNM_EXPR_EVAL_PERMIT_NON_SCALAR | GNM_EXPR_EVAL_PERMIT_EMPTY | GNM_EXPR_EVAL_ARRAY_CONTEXT); if (NULL == v) return NULL; uc.date_conv = workbook_date_conv (sv->sheet->workbook); uc.hash = g_hash_table_new_full ((GHashFunc)value_hash, (GEqualFunc)value_equal, (GDestroyNotify)value_release, (GDestroyNotify)g_free); value_area_foreach (v, &ep, CELL_ITER_IGNORE_BLANK, (GnmValueIterFunc) cb_collect_unique, &uc); value_release (v); sorted = g_ptr_array_new (); g_hash_table_foreach (uc.hash, (GHFunc)cb_hash_domain, sorted); qsort (&g_ptr_array_index (sorted, 0), sorted->len, sizeof (char *), &value_cmp); model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, gnm_value_get_type ()); cur_val = sheet_cell_get_value (ep.sheet, ep.eval.col, ep.eval.row); for (i = 0; i < sorted->len ; i++) { char *label = NULL; unsigned const max = 50; char const *str = g_hash_table_lookup (uc.hash, (v = g_ptr_array_index (sorted, i))); gsize len = g_utf8_strlen (str, -1); if (len > max + 3) { label = g_strdup (str); strcpy (g_utf8_offset_to_pointer (label, max), "..."); } gtk_list_store_append (model, &iter); gtk_list_store_set (model, &iter, 0, label ? label : str, /* Menu text */ 1, str, /* Actual string selected on. */ -1); g_free (label); if (i == 10) *clip = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); if (cur_val != NULL && v != NULL && value_equal (cur_val, v)) { gtk_tree_path_free (*select); *select = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); } } g_hash_table_destroy (uc.hash); g_ptr_array_free (sorted, TRUE); list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (model); gtk_tree_view_append_column (GTK_TREE_VIEW (list), gtk_tree_view_column_new_with_attributes ("ID", gtk_cell_renderer_text_new (), "text", 0, NULL)); return list; }
gboolean oracle_session_open (GSQLEOracleSession *oracle_session, gchar *username, gchar *password, gchar *database, gchar *buffer) { GSQL_TRACE_FUNC; unsigned char buf[64]; gint ret; /* initialize the mode to be the threaded and object environment */ if ( OCIEnvNlsCreate(&(oracle_session->envhp), OCI_THREADED|OCI_OBJECT, (dvoid *)0, 0, 0, 0, (size_t) 0, (dvoid **)0, 0, 0) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIEnvNlsCreate... failed"); return FALSE; }; /* allocate a server handle */ if ( OCIHandleAlloc ((dvoid *)(oracle_session->envhp), (dvoid **)&(oracle_session->srvhp), OCI_HTYPE_SERVER, 0, (dvoid **) 0) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a server handle)... failed"); return FALSE; }; /* allocate an error handle */ if ( OCIHandleAlloc ((dvoid *)(oracle_session->envhp), (dvoid **)&(oracle_session->errhp), OCI_HTYPE_ERROR, 0, (dvoid **) 0) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIHandleAlloc (allocate an error handle)... failed"); return FALSE; }; /* create a server context */ if ( OCIServerAttach (oracle_session->srvhp, oracle_session->errhp, (text *) database, g_utf8_strlen (database, 64), OCI_DEFAULT) == OCI_ERROR ) { g_snprintf (buffer, 256, "%s", oracle_get_error_string(oracle_session->errhp) ); return FALSE; }; /* allocate a service handle */ if ( OCIHandleAlloc ((dvoid *) (oracle_session->envhp), (dvoid **)&(oracle_session->svchp), OCI_HTYPE_SVCCTX, 0, (dvoid **) 0) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a service handle)... failed"); return FALSE; }; /* set the server attribute in the service context handle*/ if ( OCIAttrSet ((dvoid *) oracle_session->svchp, OCI_HTYPE_SVCCTX, (dvoid *) oracle_session->srvhp, (ub4) 0, OCI_ATTR_SERVER, oracle_session->errhp) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIAttrSet... failed"); return FALSE; }; /* allocate a user session handle */ if ( OCIHandleAlloc ((dvoid *) (oracle_session->envhp), (dvoid **)&(oracle_session->usrhp), OCI_HTYPE_SESSION, 0, (dvoid **) 0) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIHandleAlloc (allocate a user session handle)... failed"); return FALSE; }; /* set user name attribute in user session handle */ if ( OCIAttrSet ((dvoid *) oracle_session->usrhp, OCI_HTYPE_SESSION, (dvoid *) username, (ub4) g_utf8_strlen(username, 64), OCI_ATTR_USERNAME, oracle_session->errhp) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIAttrSet (OCI_ATTR_USERNAME)... failed"); return FALSE; }; /* set password attribute in user session handle */ if ( OCIAttrSet ((dvoid *)(oracle_session->usrhp), OCI_HTYPE_SESSION, (dvoid *)password, (ub4) g_utf8_strlen(password, 64), OCI_ATTR_PASSWORD, oracle_session->errhp) == OCI_ERROR ) { g_snprintf (buffer, 256,"OCIAttrSet(OCI_ATTR_PASSWORD)... failed"); return FALSE; }; /* make the connection*/ if ( OCISessionBegin ((dvoid *) oracle_session->svchp, oracle_session->errhp, oracle_session->usrhp, OCI_CRED_RDBMS, oracle_session->mode) == OCI_ERROR ) { g_snprintf (buffer, 256, "%s", oracle_get_error_string(oracle_session->errhp) ); return FALSE; }; oracle_client_info(oracle_session->client_version); if ( OCIAttrSet ((dvoid *)(oracle_session->usrhp), OCI_HTYPE_SESSION, (dvoid *) oracle_session->client_version, (ub4) g_utf8_strlen(oracle_session->client_version, 64), OCI_ATTR_CLIENT_INFO, oracle_session->errhp) == OCI_ERROR ) { g_snprintf (buffer, 256, "OCIAttrSet(OCI_ATTR_CLIENT_INFO)... failed"); return FALSE; }; /* set the user session attribute in the service context handle*/ if ( OCIAttrSet ((dvoid *)oracle_session->svchp, OCI_HTYPE_SVCCTX, (dvoid *) oracle_session->usrhp, (ub4) 0, OCI_ATTR_SESSION, oracle_session->errhp) == OCI_ERROR ) { g_snprintf (buffer, 256, "OCIAttrSet (OCI_ATTR_SESSION)... failed"); return FALSE; }; OCIServerVersion ((dvoid *) oracle_session->svchp, oracle_session->errhp, oracle_session->server_version, 1024, OCI_HTYPE_SVCCTX); GSQL_DEBUG ("oracle_session->server_version=[%s]", oracle_session->server_version); oracle_session->dbms_output = FALSE; oracle_session->debug_mode = FALSE; return TRUE; };
/** * find: * @callback_data: TRUE if I have to continue a previous search * * Search operation. */ void find (GtkWidget *widget, gpointer callback_data) { guint again = GPOINTER_TO_UINT(callback_data); static gboolean only_current, case_sens; gint found, offset = 0; guchar *buf; GtkTextIter position; GtkTextMark *cursor, *endsel; GtkWidget *parent = gtk_widget_get_toplevel(widget); if (!again) if (!grg_find_dialog (&needle, &only_current, &case_sens, GTK_WINDOW (parent))) return; buf = grg_entries_get_Body (); if (((current_mode == SIMPLE_ENTRY) && GTK_WIDGET_HAS_FOCUS (simpleSheet))/* || ((current_mode == STRUCT_ENTRY) && GTK_WIDGET_HAS_FOCUS (structSheet))*/) { cursor = gtk_text_buffer_get_mark (entryBuf, "insert"); gtk_text_buffer_get_iter_at_mark (entryBuf, &position, cursor); offset = gtk_text_iter_get_offset (&position); } while (TRUE) { found = grg_entries_find (needle, offset, only_current, case_sens); if (found >= 0) { buf = grg_entries_get_Body (); g_signal_handler_block (entryBuf, simpleSigID); gtk_text_buffer_set_text (entryBuf, buf, -1); g_signal_handler_unblock (entryBuf, simpleSigID); //to avoid that searching again and again the same text finds //the same portion, we set the cursor AFTER the found text cursor = gtk_text_buffer_get_mark (entryBuf, "insert"); gtk_text_buffer_get_iter_at_mark (entryBuf, &position, cursor); endsel = gtk_text_buffer_get_mark (entryBuf, "selection_bound"); gtk_text_iter_set_offset (&position, found); gtk_text_buffer_move_mark (entryBuf, cursor, &position); gtk_text_iter_set_offset (&position, found + g_utf8_strlen (needle, -1)); gtk_text_buffer_move_mark (entryBuf, endsel, &position); break; } else { if (only_current) { grg_msg (_ ("The text searched could not be found!"), GTK_MESSAGE_ERROR, parent); break; } else { if (grg_ask_dialog (_("Wrap around?"), _("Text not found. Continue search from beginning?"), FALSE, parent) == GRG_YES) { grg_entries_first (); offset = 0; continue; } else break; } } } }