toolkit/crashreporter/client/crashreporter_linux.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/client/crashreporter_linux.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,561 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <dlfcn.h>
    1.10 +#include <fcntl.h>
    1.11 +#include <glib.h>
    1.12 +#include <gtk/gtk.h>
    1.13 +#include <string.h>
    1.14 +
    1.15 +#include <cctype>
    1.16 +
    1.17 +#include "mozilla/NullPtr.h"
    1.18 +#include "crashreporter.h"
    1.19 +#include "crashreporter_gtk_common.h"
    1.20 +
    1.21 +using std::string;
    1.22 +using std::vector;
    1.23 +
    1.24 +using namespace CrashReporter;
    1.25 +
    1.26 +static GtkWidget* gViewReportButton = 0;
    1.27 +static GtkWidget* gCommentTextLabel = 0;
    1.28 +static GtkWidget* gCommentText = 0;
    1.29 +static GtkWidget* gEmailMeCheck = 0;
    1.30 +static GtkWidget* gEmailEntryLabel = 0;
    1.31 +static GtkWidget* gEmailEntry = 0;
    1.32 +
    1.33 +static bool gEmailFieldHint = true;
    1.34 +static bool gCommentFieldHint = true;
    1.35 +
    1.36 +// handle from dlopen'ing libgnome
    1.37 +static void* gnomeLib = nullptr;
    1.38 +// handle from dlopen'ing libgnomeui
    1.39 +static void* gnomeuiLib = nullptr;
    1.40 +
    1.41 +static void LoadSettings()
    1.42 +{
    1.43 +  /*
    1.44 +   * NOTE! This code needs to stay in sync with the preference checking
    1.45 +   *       code in in nsExceptionHandler.cpp.
    1.46 +   */
    1.47 +
    1.48 +  StringTable settings;
    1.49 +  if (ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true)) {
    1.50 +    if (settings.find("Email") != settings.end()) {
    1.51 +      gtk_entry_set_text(GTK_ENTRY(gEmailEntry), settings["Email"].c_str());
    1.52 +      gEmailFieldHint = false;
    1.53 +    }
    1.54 +    if (settings.find("EmailMe") != settings.end()) {
    1.55 +      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gEmailMeCheck),
    1.56 +                                   settings["EmailMe"][0] != '0');
    1.57 +    }
    1.58 +    if (settings.find("IncludeURL") != settings.end() &&
    1.59 +        gIncludeURLCheck != 0) {
    1.60 +      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gIncludeURLCheck),
    1.61 +                                   settings["IncludeURL"][0] != '0');
    1.62 +    }
    1.63 +    bool enabled;
    1.64 +    if (settings.find("SubmitReport") != settings.end())
    1.65 +      enabled = settings["SubmitReport"][0] != '0';
    1.66 +    else
    1.67 +      enabled = ShouldEnableSending();
    1.68 +    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck),
    1.69 +                                 enabled);
    1.70 +  }
    1.71 +}
    1.72 +
    1.73 +void SaveSettings()
    1.74 +{
    1.75 +  /*
    1.76 +   * NOTE! This code needs to stay in sync with the preference setting
    1.77 +   *       code in in nsExceptionHandler.cpp.
    1.78 +   */
    1.79 +
    1.80 +  StringTable settings;
    1.81 +
    1.82 +  ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true);
    1.83 +  if (!gEmailFieldHint)
    1.84 +    settings["Email"] = gtk_entry_get_text(GTK_ENTRY(gEmailEntry));
    1.85 +  else
    1.86 +    settings.erase("Email");
    1.87 +
    1.88 +  settings["EmailMe"] =
    1.89 +    gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck)) ? "1" : "0";
    1.90 +  if (gIncludeURLCheck != 0)
    1.91 +    settings["IncludeURL"] =
    1.92 +      gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gIncludeURLCheck))
    1.93 +      ? "1" : "0";
    1.94 +  settings["SubmitReport"] =
    1.95 +    gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))
    1.96 +    ? "1" : "0";
    1.97 +
    1.98 +  WriteStringsToFile(gSettingsPath + "/" + kIniFile,
    1.99 +                     "Crash Reporter", settings, true);
   1.100 +}
   1.101 +
   1.102 +void SendReport()
   1.103 +{
   1.104 +  // disable all our gui controls, show the throbber + change the progress text
   1.105 +  gtk_widget_set_sensitive(gSubmitReportCheck, FALSE);
   1.106 +  gtk_widget_set_sensitive(gViewReportButton, FALSE);
   1.107 +  gtk_widget_set_sensitive(gCommentText, FALSE);
   1.108 +  if (gIncludeURLCheck)
   1.109 +    gtk_widget_set_sensitive(gIncludeURLCheck, FALSE);
   1.110 +  gtk_widget_set_sensitive(gEmailMeCheck, FALSE);
   1.111 +  gtk_widget_set_sensitive(gEmailEntry, FALSE);
   1.112 +  gtk_widget_set_sensitive(gCloseButton, FALSE);
   1.113 +  if (gRestartButton)
   1.114 +    gtk_widget_set_sensitive(gRestartButton, FALSE);
   1.115 +  gtk_widget_show_all(gThrobber);
   1.116 +  gtk_label_set_text(GTK_LABEL(gProgressLabel),
   1.117 +                     gStrings[ST_REPORTDURINGSUBMIT].c_str());
   1.118 +
   1.119 +#ifdef MOZ_ENABLE_GCONF
   1.120 +  LoadProxyinfo();
   1.121 +#endif
   1.122 +
   1.123 +  // and spawn a thread to do the sending
   1.124 +  GError* err;
   1.125 +  gSendThreadID = g_thread_create(SendThread, nullptr, TRUE, &err);
   1.126 +}
   1.127 +
   1.128 +static void ShowReportInfo(GtkTextView* viewReportTextView)
   1.129 +{
   1.130 +  GtkTextBuffer* buffer =
   1.131 +    gtk_text_view_get_buffer(viewReportTextView);
   1.132 +
   1.133 +  GtkTextIter start, end;
   1.134 +  gtk_text_buffer_get_start_iter(buffer, &start);
   1.135 +  gtk_text_buffer_get_end_iter(buffer, &end);
   1.136 +
   1.137 +  gtk_text_buffer_delete(buffer, &start, &end);
   1.138 +
   1.139 +  for (StringTable::iterator iter = gQueryParameters.begin();
   1.140 +       iter != gQueryParameters.end();
   1.141 +       iter++) {
   1.142 +    gtk_text_buffer_insert(buffer, &end, iter->first.c_str(), -1);
   1.143 +    gtk_text_buffer_insert(buffer, &end, ": ", -1);
   1.144 +    gtk_text_buffer_insert(buffer, &end, iter->second.c_str(), -1);
   1.145 +    gtk_text_buffer_insert(buffer, &end, "\n", -1);
   1.146 +  }
   1.147 +
   1.148 +  gtk_text_buffer_insert(buffer, &end, "\n", -1);
   1.149 +  gtk_text_buffer_insert(buffer, &end,
   1.150 +                         gStrings[ST_EXTRAREPORTINFO].c_str(), -1);
   1.151 +}
   1.152 +
   1.153 +void UpdateSubmit()
   1.154 +{
   1.155 +  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))) {
   1.156 +    gtk_widget_set_sensitive(gViewReportButton, TRUE);
   1.157 +    gtk_widget_set_sensitive(gCommentText, TRUE);
   1.158 +    if (gIncludeURLCheck)
   1.159 +      gtk_widget_set_sensitive(gIncludeURLCheck, TRUE);
   1.160 +    gtk_widget_set_sensitive(gEmailMeCheck, TRUE);
   1.161 +    gtk_widget_set_sensitive(gEmailEntry,
   1.162 +                             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck)));
   1.163 +    gtk_label_set_text(GTK_LABEL(gProgressLabel),
   1.164 +                       gStrings[ST_REPORTPRESUBMIT].c_str());
   1.165 +  } else {
   1.166 +    gtk_widget_set_sensitive(gViewReportButton, FALSE);
   1.167 +    gtk_widget_set_sensitive(gCommentText, FALSE);
   1.168 +    if (gIncludeURLCheck)
   1.169 +      gtk_widget_set_sensitive(gIncludeURLCheck, FALSE);
   1.170 +    gtk_widget_set_sensitive(gEmailMeCheck, FALSE);
   1.171 +    gtk_widget_set_sensitive(gEmailEntry, FALSE);
   1.172 +    gtk_label_set_text(GTK_LABEL(gProgressLabel), "");
   1.173 +  }
   1.174 +}
   1.175 +
   1.176 +static void ViewReportClicked(GtkButton* button,
   1.177 +                              gpointer userData)
   1.178 +{
   1.179 +  GtkDialog* dialog =
   1.180 +    GTK_DIALOG(gtk_dialog_new_with_buttons(gStrings[ST_VIEWREPORTTITLE].c_str(),
   1.181 +                                           GTK_WINDOW(gWindow),
   1.182 +                                           GTK_DIALOG_MODAL,
   1.183 +                                           GTK_STOCK_OK,
   1.184 +                                           GTK_RESPONSE_OK,
   1.185 +                                           nullptr));
   1.186 +
   1.187 +  GtkWidget* scrolled = gtk_scrolled_window_new(0, 0);
   1.188 +  gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), scrolled);
   1.189 +  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
   1.190 +                                 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
   1.191 +  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
   1.192 +                                      GTK_SHADOW_IN);
   1.193 +
   1.194 +  GtkWidget* viewReportTextView = gtk_text_view_new();
   1.195 +  gtk_container_add(GTK_CONTAINER(scrolled), viewReportTextView);
   1.196 +  gtk_text_view_set_editable(GTK_TEXT_VIEW(viewReportTextView), FALSE);
   1.197 +  gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(viewReportTextView),
   1.198 +                              GTK_WRAP_WORD);
   1.199 +  gtk_widget_set_size_request(GTK_WIDGET(viewReportTextView), -1, 100);
   1.200 +
   1.201 +  ShowReportInfo(GTK_TEXT_VIEW(viewReportTextView));
   1.202 +
   1.203 +  gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK);
   1.204 +  gtk_widget_set_size_request(GTK_WIDGET(dialog), 400, 200);
   1.205 +  gtk_widget_show_all(GTK_WIDGET(dialog));
   1.206 +  gtk_dialog_run(dialog);
   1.207 +  gtk_widget_destroy(GTK_WIDGET(dialog));
   1.208 +}
   1.209 +
   1.210 +static void CommentChanged(GtkTextBuffer* buffer, gpointer userData)
   1.211 +{
   1.212 +  GtkTextIter start, end;
   1.213 +  gtk_text_buffer_get_start_iter(buffer, &start);
   1.214 +  gtk_text_buffer_get_end_iter(buffer, &end);
   1.215 +  const char* comment = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
   1.216 +  if (comment[0] == '\0' || gCommentFieldHint)
   1.217 +    gQueryParameters.erase("Comments");
   1.218 +  else
   1.219 +    gQueryParameters["Comments"] = comment;
   1.220 +}
   1.221 +
   1.222 +static void CommentInsert(GtkTextBuffer* buffer,
   1.223 +                          GtkTextIter* location,
   1.224 +                          gchar* text,
   1.225 +                          gint len,
   1.226 +                          gpointer userData)
   1.227 +{
   1.228 +  GtkTextIter start, end;
   1.229 +  gtk_text_buffer_get_start_iter(buffer, &start);
   1.230 +  gtk_text_buffer_get_end_iter(buffer, &end);
   1.231 +  const char* comment = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
   1.232 +
   1.233 +  // limit to 500 bytes in utf-8
   1.234 +  if (strlen(comment) + len > MAX_COMMENT_LENGTH) {
   1.235 +    g_signal_stop_emission_by_name(buffer, "insert-text");
   1.236 +  }
   1.237 +}
   1.238 +
   1.239 +static void UpdateHintText(GtkWidget* widget, gboolean gainedFocus,
   1.240 +                           bool* hintShowing, const char* hintText)
   1.241 +{
   1.242 +  GtkTextBuffer* buffer = nullptr;
   1.243 +  if (GTK_IS_TEXT_VIEW(widget))
   1.244 +    buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
   1.245 +
   1.246 +  if (gainedFocus) {
   1.247 +    if (*hintShowing) {
   1.248 +      if (buffer == nullptr) { // sort of cheating
   1.249 +        gtk_entry_set_text(GTK_ENTRY(widget), "");
   1.250 +      }
   1.251 +      else { // GtkTextView
   1.252 +        gtk_text_buffer_set_text(buffer, "", 0);
   1.253 +      }
   1.254 +      gtk_widget_modify_text(widget, GTK_STATE_NORMAL, nullptr);
   1.255 +      *hintShowing = false;
   1.256 +    }
   1.257 +  }
   1.258 +  else {
   1.259 +    // lost focus
   1.260 +    const char* text = nullptr;
   1.261 +    if (buffer == nullptr) {
   1.262 +      text = gtk_entry_get_text(GTK_ENTRY(widget));
   1.263 +    }
   1.264 +    else {
   1.265 +      GtkTextIter start, end;
   1.266 +      gtk_text_buffer_get_start_iter(buffer, &start);
   1.267 +      gtk_text_buffer_get_end_iter(buffer, &end);
   1.268 +      text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
   1.269 +    }
   1.270 +
   1.271 +    if (text == nullptr || text[0] == '\0') {
   1.272 +      *hintShowing = true;
   1.273 +
   1.274 +      if (buffer == nullptr) {
   1.275 +        gtk_entry_set_text(GTK_ENTRY(widget), hintText);
   1.276 +      }
   1.277 +      else {
   1.278 +        gtk_text_buffer_set_text(buffer, hintText, -1);
   1.279 +      }
   1.280 +
   1.281 +      gtk_widget_modify_text(widget, GTK_STATE_NORMAL,
   1.282 +                              &gtk_widget_get_style(widget)->text[GTK_STATE_INSENSITIVE]);
   1.283 +    }
   1.284 +  }
   1.285 +}
   1.286 +
   1.287 +static gboolean CommentFocusChange(GtkWidget* widget, GdkEventFocus* event,
   1.288 +                                   gpointer userData)
   1.289 +{
   1.290 +  UpdateHintText(widget, event->in, &gCommentFieldHint,
   1.291 +                 gStrings[ST_COMMENTGRAYTEXT].c_str());
   1.292 +
   1.293 +  return FALSE;
   1.294 +}
   1.295 +
   1.296 +static void UpdateEmail()
   1.297 +{
   1.298 +  const char* email = gtk_entry_get_text(GTK_ENTRY(gEmailEntry));
   1.299 +  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck))) {
   1.300 +    gtk_widget_set_sensitive(gEmailEntry, TRUE);
   1.301 +  } else {
   1.302 +    email = "";
   1.303 +    gtk_widget_set_sensitive(gEmailEntry, FALSE);
   1.304 +  }
   1.305 +  if (email[0] == '\0' || gEmailFieldHint)
   1.306 +    gQueryParameters.erase("Email");
   1.307 +  else
   1.308 +    gQueryParameters["Email"] = email;
   1.309 +}
   1.310 +
   1.311 +static void EmailMeClicked(GtkButton* sender, gpointer userData)
   1.312 +{
   1.313 +  UpdateEmail();
   1.314 +}
   1.315 +
   1.316 +static void EmailChanged(GtkEditable* editable, gpointer userData)
   1.317 +{
   1.318 +  UpdateEmail();
   1.319 +}
   1.320 +
   1.321 +static gboolean EmailFocusChange(GtkWidget* widget, GdkEventFocus* event,
   1.322 +                         gpointer userData)
   1.323 +{
   1.324 +  UpdateHintText(widget, event->in, &gEmailFieldHint,
   1.325 +                 gStrings[ST_EMAILGRAYTEXT].c_str());
   1.326 +
   1.327 +  return FALSE;
   1.328 +}
   1.329 +
   1.330 +typedef struct _GnomeProgram GnomeProgram;
   1.331 +typedef struct _GnomeModuleInfo GnomeModuleInfo;
   1.332 +typedef GnomeProgram * (*_gnome_program_init_fn)(const char *, const char *,
   1.333 +                                                 const GnomeModuleInfo *, int,
   1.334 +                                                 char **, const char *, ...);
   1.335 +typedef const GnomeModuleInfo * (*_libgnomeui_module_info_get_fn)();
   1.336 +
   1.337 +void TryInitGnome()
   1.338 +{
   1.339 +  gnomeLib = dlopen("libgnome-2.so.0", RTLD_LAZY);
   1.340 +  if (!gnomeLib)
   1.341 +    return;
   1.342 +
   1.343 +  gnomeuiLib = dlopen("libgnomeui-2.so.0", RTLD_LAZY);
   1.344 +  if (!gnomeuiLib)
   1.345 +    return;
   1.346 +
   1.347 +  _gnome_program_init_fn gnome_program_init =
   1.348 +    (_gnome_program_init_fn)(dlsym(gnomeLib, "gnome_program_init"));
   1.349 +  _libgnomeui_module_info_get_fn libgnomeui_module_info_get =
   1.350 +    (_libgnomeui_module_info_get_fn)(dlsym(gnomeuiLib, "libgnomeui_module_info_get"));
   1.351 +
   1.352 +  if (gnome_program_init && libgnomeui_module_info_get) {
   1.353 +    gnome_program_init("crashreporter", "1.0", libgnomeui_module_info_get(),
   1.354 +                       gArgc, gArgv, nullptr);
   1.355 +  }
   1.356 +
   1.357 +}
   1.358 +
   1.359 +/* === Crashreporter UI Functions === */
   1.360 +
   1.361 +/*
   1.362 + * Anything not listed here is in crashreporter_gtk_common.cpp:
   1.363 + *  UIInit
   1.364 + *  UIShowDefaultUI
   1.365 + *  UIError_impl
   1.366 + *  UIGetIniPath
   1.367 + *  UIGetSettingsPath
   1.368 + *  UIEnsurePathExists
   1.369 + *  UIFileExists
   1.370 + *  UIMoveFile
   1.371 + *  UIDeleteFile
   1.372 + *  UIOpenRead
   1.373 + *  UIOpenWrite
   1.374 + */
   1.375 +
   1.376 +void UIShutdown()
   1.377 +{
   1.378 +  if (gnomeuiLib)
   1.379 +    dlclose(gnomeuiLib);
   1.380 +  // Don't dlclose gnomeLib as libgnomevfs and libORBit-2 use atexit().
   1.381 +}
   1.382 +
   1.383 +bool UIShowCrashUI(const string& dumpfile,
   1.384 +                   const StringTable& queryParameters,
   1.385 +                   const string& sendURL,
   1.386 +                   const vector<string>& restartArgs)
   1.387 +{
   1.388 +  gDumpFile = dumpfile;
   1.389 +  gQueryParameters = queryParameters;
   1.390 +  gSendURL = sendURL;
   1.391 +  gRestartArgs = restartArgs;
   1.392 +  if (gQueryParameters.find("URL") != gQueryParameters.end())
   1.393 +    gURLParameter = gQueryParameters["URL"];
   1.394 +
   1.395 +  gWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   1.396 +  gtk_window_set_title(GTK_WINDOW(gWindow),
   1.397 +                       gStrings[ST_CRASHREPORTERTITLE].c_str());
   1.398 +  gtk_window_set_resizable(GTK_WINDOW(gWindow), FALSE);
   1.399 +  gtk_window_set_position(GTK_WINDOW(gWindow), GTK_WIN_POS_CENTER);
   1.400 +  gtk_container_set_border_width(GTK_CONTAINER(gWindow), 12);
   1.401 +  g_signal_connect(gWindow, "delete-event", G_CALLBACK(WindowDeleted), 0);
   1.402 +  g_signal_connect(gWindow, "key_press_event", G_CALLBACK(check_escape), nullptr);
   1.403 +
   1.404 +  GtkWidget* vbox = gtk_vbox_new(FALSE, 6);
   1.405 +  gtk_container_add(GTK_CONTAINER(gWindow), vbox);
   1.406 +
   1.407 +  GtkWidget* titleLabel = gtk_label_new("");
   1.408 +  gtk_box_pack_start(GTK_BOX(vbox), titleLabel, FALSE, FALSE, 0);
   1.409 +  gtk_misc_set_alignment(GTK_MISC(titleLabel), 0, 0.5);
   1.410 +  char* markup = g_strdup_printf("<b>%s</b>",
   1.411 +                                 gStrings[ST_CRASHREPORTERHEADER].c_str());
   1.412 +  gtk_label_set_markup(GTK_LABEL(titleLabel), markup);
   1.413 +  g_free(markup);
   1.414 +
   1.415 +  GtkWidget* descriptionLabel =
   1.416 +    gtk_label_new(gStrings[ST_CRASHREPORTERDESCRIPTION].c_str());
   1.417 +  gtk_box_pack_start(GTK_BOX(vbox), descriptionLabel, TRUE, TRUE, 0);
   1.418 +  // force the label to line wrap
   1.419 +  gtk_widget_set_size_request(descriptionLabel, 400, -1);
   1.420 +  gtk_label_set_line_wrap(GTK_LABEL(descriptionLabel), TRUE);
   1.421 +  gtk_label_set_selectable(GTK_LABEL(descriptionLabel), TRUE);
   1.422 +  gtk_misc_set_alignment(GTK_MISC(descriptionLabel), 0, 0.5);
   1.423 +
   1.424 +  // this is honestly how they suggest you indent a section
   1.425 +  GtkWidget* indentBox = gtk_hbox_new(FALSE, 0);
   1.426 +  gtk_box_pack_start(GTK_BOX(vbox), indentBox, FALSE, FALSE, 0);
   1.427 +  gtk_box_pack_start(GTK_BOX(indentBox), gtk_label_new(""), FALSE, FALSE, 6);
   1.428 +
   1.429 +  GtkWidget* innerVBox1 = gtk_vbox_new(FALSE, 0);
   1.430 +  gtk_box_pack_start(GTK_BOX(indentBox), innerVBox1, TRUE, TRUE, 0);
   1.431 +
   1.432 +  gSubmitReportCheck =
   1.433 +    gtk_check_button_new_with_label(gStrings[ST_CHECKSUBMIT].c_str());
   1.434 +  gtk_box_pack_start(GTK_BOX(innerVBox1), gSubmitReportCheck, FALSE, FALSE, 0);
   1.435 +  g_signal_connect(gSubmitReportCheck, "clicked",
   1.436 +                   G_CALLBACK(SubmitReportChecked), 0);
   1.437 +
   1.438 +  // indent again, below the "submit report" checkbox
   1.439 +  GtkWidget* indentBox2 = gtk_hbox_new(FALSE, 0);
   1.440 +  gtk_box_pack_start(GTK_BOX(innerVBox1), indentBox2, FALSE, FALSE, 0);
   1.441 +  gtk_box_pack_start(GTK_BOX(indentBox2), gtk_label_new(""), FALSE, FALSE, 6);
   1.442 +
   1.443 +  GtkWidget* innerVBox = gtk_vbox_new(FALSE, 0);
   1.444 +  gtk_box_pack_start(GTK_BOX(indentBox2), innerVBox, TRUE, TRUE, 0);
   1.445 +  gtk_box_set_spacing(GTK_BOX(innerVBox), 6);
   1.446 +
   1.447 +  GtkWidget* viewReportButtonBox = gtk_hbutton_box_new();
   1.448 +  gtk_box_pack_start(GTK_BOX(innerVBox), viewReportButtonBox, FALSE, FALSE, 0);
   1.449 +  gtk_box_set_spacing(GTK_BOX(viewReportButtonBox), 6);
   1.450 +  gtk_button_box_set_layout(GTK_BUTTON_BOX(viewReportButtonBox), GTK_BUTTONBOX_START);
   1.451 +
   1.452 +  gViewReportButton =
   1.453 +    gtk_button_new_with_label(gStrings[ST_VIEWREPORT].c_str());
   1.454 +  gtk_box_pack_start(GTK_BOX(viewReportButtonBox), gViewReportButton, FALSE, FALSE, 0);
   1.455 +  g_signal_connect(gViewReportButton, "clicked", G_CALLBACK(ViewReportClicked), 0);
   1.456 +
   1.457 +  GtkWidget* scrolled = gtk_scrolled_window_new(0, 0);
   1.458 +  gtk_container_add(GTK_CONTAINER(innerVBox), scrolled);
   1.459 +  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
   1.460 +                                 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
   1.461 +  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
   1.462 +                                      GTK_SHADOW_IN);
   1.463 +
   1.464 +  gCommentTextLabel = gtk_label_new(gStrings[ST_COMMENTGRAYTEXT].c_str());
   1.465 +  gCommentText = gtk_text_view_new();
   1.466 +  gtk_label_set_mnemonic_widget(GTK_LABEL(gCommentTextLabel), gCommentText);
   1.467 +  gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(gCommentText), FALSE);
   1.468 +  g_signal_connect(gCommentText, "focus-in-event", G_CALLBACK(CommentFocusChange), 0);
   1.469 +  g_signal_connect(gCommentText, "focus-out-event", G_CALLBACK(CommentFocusChange), 0);
   1.470 +
   1.471 +  GtkTextBuffer* commentBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gCommentText));
   1.472 +  g_signal_connect(commentBuffer, "changed", G_CALLBACK(CommentChanged), 0);
   1.473 +  g_signal_connect(commentBuffer, "insert-text", G_CALLBACK(CommentInsert), 0);
   1.474 +
   1.475 +  gtk_container_add(GTK_CONTAINER(scrolled), gCommentText);
   1.476 +  gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gCommentText),
   1.477 +                              GTK_WRAP_WORD);
   1.478 +  gtk_widget_set_size_request(GTK_WIDGET(gCommentText), -1, 100);
   1.479 +
   1.480 +  if (gQueryParameters.find("URL") != gQueryParameters.end()) {
   1.481 +    gIncludeURLCheck =
   1.482 +      gtk_check_button_new_with_label(gStrings[ST_CHECKURL].c_str());
   1.483 +    gtk_box_pack_start(GTK_BOX(innerVBox), gIncludeURLCheck, FALSE, FALSE, 0);
   1.484 +    g_signal_connect(gIncludeURLCheck, "clicked", G_CALLBACK(IncludeURLClicked), 0);
   1.485 +    // on by default
   1.486 +    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gIncludeURLCheck), TRUE);
   1.487 +  }
   1.488 +
   1.489 +  gEmailMeCheck =
   1.490 +    gtk_check_button_new_with_label(gStrings[ST_CHECKEMAIL].c_str());
   1.491 +  gtk_box_pack_start(GTK_BOX(innerVBox), gEmailMeCheck, FALSE, FALSE, 0);
   1.492 +  g_signal_connect(gEmailMeCheck, "clicked", G_CALLBACK(EmailMeClicked), 0);
   1.493 +
   1.494 +  GtkWidget* emailIndentBox = gtk_hbox_new(FALSE, 0);
   1.495 +  gtk_box_pack_start(GTK_BOX(innerVBox), emailIndentBox, FALSE, FALSE, 0);
   1.496 +  gtk_box_pack_start(GTK_BOX(emailIndentBox), gtk_label_new(""),
   1.497 +                     FALSE, FALSE, 9);
   1.498 +
   1.499 +  gEmailEntryLabel = gtk_label_new(gStrings[ST_EMAILGRAYTEXT].c_str());
   1.500 +  gEmailEntry = gtk_entry_new();
   1.501 +  gtk_label_set_mnemonic_widget(GTK_LABEL(gEmailEntryLabel), gEmailEntry);
   1.502 +  gtk_box_pack_start(GTK_BOX(emailIndentBox), gEmailEntry, TRUE, TRUE, 0);
   1.503 +  g_signal_connect(gEmailEntry, "changed", G_CALLBACK(EmailChanged), 0);
   1.504 +  g_signal_connect(gEmailEntry, "focus-in-event", G_CALLBACK(EmailFocusChange), 0);
   1.505 +  g_signal_connect(gEmailEntry, "focus-out-event", G_CALLBACK(EmailFocusChange), 0);
   1.506 +
   1.507 +  GtkWidget* progressBox = gtk_hbox_new(FALSE, 6);
   1.508 +  gtk_box_pack_start(GTK_BOX(vbox), progressBox, TRUE, TRUE, 0);
   1.509 +
   1.510 +  // Get the throbber image from alongside the executable
   1.511 +  char* dir = g_path_get_dirname(gArgv[0]);
   1.512 +  char* path = g_build_filename(dir, "Throbber-small.gif", nullptr);
   1.513 +  g_free(dir);
   1.514 +  gThrobber = gtk_image_new_from_file(path);
   1.515 +  gtk_box_pack_start(GTK_BOX(progressBox), gThrobber, FALSE, FALSE, 0);
   1.516 +
   1.517 +  gProgressLabel =
   1.518 +    gtk_label_new(gStrings[ST_REPORTPRESUBMIT].c_str());
   1.519 +  gtk_box_pack_start(GTK_BOX(progressBox), gProgressLabel, TRUE, TRUE, 0);
   1.520 +  // force the label to line wrap
   1.521 +  gtk_widget_set_size_request(gProgressLabel, 400, -1);
   1.522 +  gtk_label_set_line_wrap(GTK_LABEL(gProgressLabel), TRUE);
   1.523 +
   1.524 +  GtkWidget* buttonBox = gtk_hbutton_box_new();
   1.525 +  gtk_box_pack_end(GTK_BOX(vbox), buttonBox, FALSE, FALSE, 0);
   1.526 +  gtk_box_set_spacing(GTK_BOX(buttonBox), 6);
   1.527 +  gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
   1.528 +
   1.529 +  gCloseButton =
   1.530 +    gtk_button_new_with_label(gStrings[ST_QUIT].c_str());
   1.531 +  gtk_box_pack_start(GTK_BOX(buttonBox), gCloseButton, FALSE, FALSE, 0);
   1.532 +  gtk_widget_set_can_default(gCloseButton, TRUE);
   1.533 +  g_signal_connect(gCloseButton, "clicked", G_CALLBACK(CloseClicked), 0);
   1.534 +
   1.535 +  gRestartButton = 0;
   1.536 +  if (restartArgs.size() > 0) {
   1.537 +    gRestartButton = gtk_button_new_with_label(gStrings[ST_RESTART].c_str());
   1.538 +    gtk_box_pack_start(GTK_BOX(buttonBox), gRestartButton, FALSE, FALSE, 0);
   1.539 +    gtk_widget_set_can_default(gRestartButton, TRUE);
   1.540 +    g_signal_connect(gRestartButton, "clicked", G_CALLBACK(RestartClicked), 0);
   1.541 +  }
   1.542 +
   1.543 +  gtk_widget_grab_focus(gSubmitReportCheck);
   1.544 +
   1.545 +  gtk_widget_grab_default(gRestartButton ? gRestartButton : gCloseButton);
   1.546 +
   1.547 +  LoadSettings();
   1.548 +
   1.549 +  UpdateEmail();
   1.550 +  UpdateSubmit();
   1.551 +
   1.552 +  UpdateHintText(gCommentText, FALSE, &gCommentFieldHint,
   1.553 +                 gStrings[ST_COMMENTGRAYTEXT].c_str());
   1.554 +  UpdateHintText(gEmailEntry, FALSE, &gEmailFieldHint,
   1.555 +                 gStrings[ST_EMAILGRAYTEXT].c_str());
   1.556 +
   1.557 +  gtk_widget_show_all(gWindow);
   1.558 +  // stick this here to avoid the show_all above...
   1.559 +  gtk_widget_hide(gThrobber);
   1.560 +
   1.561 +  gtk_main();
   1.562 +
   1.563 +  return gDidTrySend;
   1.564 +}

mercurial