2007-07-25 05:06:04 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-07-25 05:06:04 +04:00
|
|
|
|
2007-08-30 18:55:21 +04:00
|
|
|
#include <dlfcn.h>
|
2010-04-07 21:06:17 +04:00
|
|
|
#include <fcntl.h>
|
2008-01-23 03:06:40 +03:00
|
|
|
#include <glib.h>
|
2010-04-07 21:06:17 +04:00
|
|
|
#include <gtk/gtk.h>
|
2008-03-17 21:02:08 +03:00
|
|
|
#include <string.h>
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2010-04-07 21:06:17 +04:00
|
|
|
#include <cctype>
|
|
|
|
|
2013-10-11 15:21:52 +04:00
|
|
|
#include "mozilla/NullPtr.h"
|
2010-04-07 21:06:17 +04:00
|
|
|
#include "crashreporter.h"
|
|
|
|
#include "crashreporter_gtk_common.h"
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2007-07-25 05:06:04 +04:00
|
|
|
using std::string;
|
2007-07-25 05:06:11 +04:00
|
|
|
using std::vector;
|
2007-07-25 05:06:04 +04:00
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
using namespace CrashReporter;
|
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
static GtkWidget* gViewReportButton = 0;
|
2011-02-14 20:20:02 +03:00
|
|
|
static GtkWidget* gCommentTextLabel = 0;
|
2008-01-23 03:06:40 +03:00
|
|
|
static GtkWidget* gCommentText = 0;
|
2007-07-25 05:06:08 +04:00
|
|
|
static GtkWidget* gEmailMeCheck = 0;
|
2011-02-14 20:20:02 +03:00
|
|
|
static GtkWidget* gEmailEntryLabel = 0;
|
2007-07-25 05:06:08 +04:00
|
|
|
static GtkWidget* gEmailEntry = 0;
|
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
static bool gEmailFieldHint = true;
|
|
|
|
static bool gCommentFieldHint = true;
|
|
|
|
|
2007-08-30 18:55:21 +04:00
|
|
|
// handle from dlopen'ing libgnome
|
2013-10-11 00:39:09 +04:00
|
|
|
static void* gnomeLib = nullptr;
|
2007-08-30 18:55:21 +04:00
|
|
|
// handle from dlopen'ing libgnomeui
|
2013-10-11 00:39:09 +04:00
|
|
|
static void* gnomeuiLib = nullptr;
|
2007-08-30 18:55:21 +04:00
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
static void LoadSettings()
|
2007-07-25 05:06:04 +04:00
|
|
|
{
|
2010-02-10 04:05:31 +03:00
|
|
|
/*
|
|
|
|
* NOTE! This code needs to stay in sync with the preference checking
|
|
|
|
* code in in nsExceptionHandler.cpp.
|
|
|
|
*/
|
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
StringTable settings;
|
|
|
|
if (ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true)) {
|
|
|
|
if (settings.find("Email") != settings.end()) {
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(gEmailEntry), settings["Email"].c_str());
|
2008-01-23 03:06:40 +03:00
|
|
|
gEmailFieldHint = false;
|
2007-07-25 05:06:08 +04:00
|
|
|
}
|
|
|
|
if (settings.find("EmailMe") != settings.end()) {
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gEmailMeCheck),
|
|
|
|
settings["EmailMe"][0] != '0');
|
|
|
|
}
|
2007-11-29 20:35:44 +03:00
|
|
|
if (settings.find("IncludeURL") != settings.end() &&
|
|
|
|
gIncludeURLCheck != 0) {
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gIncludeURLCheck),
|
|
|
|
settings["IncludeURL"][0] != '0');
|
|
|
|
}
|
2008-04-08 01:18:06 +04:00
|
|
|
bool enabled;
|
|
|
|
if (settings.find("SubmitReport") != settings.end())
|
|
|
|
enabled = settings["SubmitReport"][0] != '0';
|
|
|
|
else
|
|
|
|
enabled = ShouldEnableSending();
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck),
|
|
|
|
enabled);
|
2007-07-25 05:06:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-07 21:06:17 +04:00
|
|
|
void SaveSettings()
|
2007-07-25 05:06:08 +04:00
|
|
|
{
|
2010-02-10 04:05:31 +03:00
|
|
|
/*
|
|
|
|
* NOTE! This code needs to stay in sync with the preference setting
|
|
|
|
* code in in nsExceptionHandler.cpp.
|
|
|
|
*/
|
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
StringTable settings;
|
|
|
|
|
|
|
|
ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true);
|
2008-01-23 03:06:40 +03:00
|
|
|
if (!gEmailFieldHint)
|
|
|
|
settings["Email"] = gtk_entry_get_text(GTK_ENTRY(gEmailEntry));
|
|
|
|
else
|
|
|
|
settings.erase("Email");
|
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
settings["EmailMe"] =
|
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck)) ? "1" : "0";
|
2007-11-29 20:35:44 +03:00
|
|
|
if (gIncludeURLCheck != 0)
|
|
|
|
settings["IncludeURL"] =
|
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gIncludeURLCheck))
|
|
|
|
? "1" : "0";
|
2007-07-25 05:06:08 +04:00
|
|
|
settings["SubmitReport"] =
|
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))
|
|
|
|
? "1" : "0";
|
|
|
|
|
|
|
|
WriteStringsToFile(gSettingsPath + "/" + kIniFile,
|
|
|
|
"Crash Reporter", settings, true);
|
|
|
|
}
|
|
|
|
|
2010-04-07 21:06:17 +04:00
|
|
|
void SendReport()
|
2007-07-25 05:06:08 +04:00
|
|
|
{
|
2008-01-23 03:06:40 +03:00
|
|
|
// disable all our gui controls, show the throbber + change the progress text
|
|
|
|
gtk_widget_set_sensitive(gSubmitReportCheck, FALSE);
|
|
|
|
gtk_widget_set_sensitive(gViewReportButton, FALSE);
|
|
|
|
gtk_widget_set_sensitive(gCommentText, FALSE);
|
2009-09-28 02:32:49 +04:00
|
|
|
if (gIncludeURLCheck)
|
|
|
|
gtk_widget_set_sensitive(gIncludeURLCheck, FALSE);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_set_sensitive(gEmailMeCheck, FALSE);
|
|
|
|
gtk_widget_set_sensitive(gEmailEntry, FALSE);
|
|
|
|
gtk_widget_set_sensitive(gCloseButton, FALSE);
|
2009-09-28 02:32:49 +04:00
|
|
|
if (gRestartButton)
|
|
|
|
gtk_widget_set_sensitive(gRestartButton, FALSE);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_show_all(gThrobber);
|
|
|
|
gtk_label_set_text(GTK_LABEL(gProgressLabel),
|
|
|
|
gStrings[ST_REPORTDURINGSUBMIT].c_str());
|
|
|
|
|
2009-09-28 02:33:06 +04:00
|
|
|
#ifdef MOZ_ENABLE_GCONF
|
|
|
|
LoadProxyinfo();
|
|
|
|
#endif
|
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
// and spawn a thread to do the sending
|
|
|
|
GError* err;
|
2013-10-11 00:39:09 +04:00
|
|
|
gSendThreadID = g_thread_create(SendThread, nullptr, TRUE, &err);
|
2007-07-25 05:06:08 +04:00
|
|
|
}
|
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
static void ShowReportInfo(GtkTextView* viewReportTextView)
|
2007-07-25 05:06:08 +04:00
|
|
|
{
|
|
|
|
GtkTextBuffer* buffer =
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_text_view_get_buffer(viewReportTextView);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
GtkTextIter start, end;
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &end);
|
|
|
|
|
|
|
|
gtk_text_buffer_delete(buffer, &start, &end);
|
|
|
|
|
|
|
|
for (StringTable::iterator iter = gQueryParameters.begin();
|
|
|
|
iter != gQueryParameters.end();
|
|
|
|
iter++) {
|
|
|
|
gtk_text_buffer_insert(buffer, &end, iter->first.c_str(), -1);
|
|
|
|
gtk_text_buffer_insert(buffer, &end, ": ", -1);
|
|
|
|
gtk_text_buffer_insert(buffer, &end, iter->second.c_str(), -1);
|
|
|
|
gtk_text_buffer_insert(buffer, &end, "\n", -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_buffer_insert(buffer, &end, "\n", -1);
|
|
|
|
gtk_text_buffer_insert(buffer, &end,
|
|
|
|
gStrings[ST_EXTRAREPORTINFO].c_str(), -1);
|
|
|
|
}
|
|
|
|
|
2010-04-07 21:06:17 +04:00
|
|
|
void UpdateSubmit()
|
2008-01-23 03:06:40 +03:00
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))) {
|
|
|
|
gtk_widget_set_sensitive(gViewReportButton, TRUE);
|
|
|
|
gtk_widget_set_sensitive(gCommentText, TRUE);
|
2009-09-28 02:32:49 +04:00
|
|
|
if (gIncludeURLCheck)
|
|
|
|
gtk_widget_set_sensitive(gIncludeURLCheck, TRUE);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_set_sensitive(gEmailMeCheck, TRUE);
|
|
|
|
gtk_widget_set_sensitive(gEmailEntry,
|
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck)));
|
|
|
|
gtk_label_set_text(GTK_LABEL(gProgressLabel),
|
|
|
|
gStrings[ST_REPORTPRESUBMIT].c_str());
|
|
|
|
} else {
|
|
|
|
gtk_widget_set_sensitive(gViewReportButton, FALSE);
|
|
|
|
gtk_widget_set_sensitive(gCommentText, FALSE);
|
2009-09-28 02:32:49 +04:00
|
|
|
if (gIncludeURLCheck)
|
|
|
|
gtk_widget_set_sensitive(gIncludeURLCheck, FALSE);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_set_sensitive(gEmailMeCheck, FALSE);
|
|
|
|
gtk_widget_set_sensitive(gEmailEntry, FALSE);
|
|
|
|
gtk_label_set_text(GTK_LABEL(gProgressLabel), "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ViewReportClicked(GtkButton* button,
|
|
|
|
gpointer userData)
|
|
|
|
{
|
|
|
|
GtkDialog* dialog =
|
|
|
|
GTK_DIALOG(gtk_dialog_new_with_buttons(gStrings[ST_VIEWREPORTTITLE].c_str(),
|
|
|
|
GTK_WINDOW(gWindow),
|
|
|
|
GTK_DIALOG_MODAL,
|
|
|
|
GTK_STOCK_OK,
|
|
|
|
GTK_RESPONSE_OK,
|
2013-10-11 00:39:09 +04:00
|
|
|
nullptr));
|
2008-01-23 03:06:40 +03:00
|
|
|
|
|
|
|
GtkWidget* scrolled = gtk_scrolled_window_new(0, 0);
|
2013-11-12 07:01:41 +04:00
|
|
|
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), scrolled);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
|
|
|
|
GtkWidget* viewReportTextView = gtk_text_view_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(scrolled), viewReportTextView);
|
|
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(viewReportTextView), FALSE);
|
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(viewReportTextView),
|
|
|
|
GTK_WRAP_WORD);
|
|
|
|
gtk_widget_set_size_request(GTK_WIDGET(viewReportTextView), -1, 100);
|
|
|
|
|
|
|
|
ShowReportInfo(GTK_TEXT_VIEW(viewReportTextView));
|
|
|
|
|
|
|
|
gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK);
|
|
|
|
gtk_widget_set_size_request(GTK_WIDGET(dialog), 400, 200);
|
|
|
|
gtk_widget_show_all(GTK_WIDGET(dialog));
|
|
|
|
gtk_dialog_run(dialog);
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(dialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CommentChanged(GtkTextBuffer* buffer, gpointer userData)
|
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &end);
|
|
|
|
const char* comment = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
|
2008-03-17 17:21:47 +03:00
|
|
|
if (comment[0] == '\0' || gCommentFieldHint)
|
2008-01-23 03:06:40 +03:00
|
|
|
gQueryParameters.erase("Comments");
|
|
|
|
else
|
|
|
|
gQueryParameters["Comments"] = comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CommentInsert(GtkTextBuffer* buffer,
|
|
|
|
GtkTextIter* location,
|
|
|
|
gchar* text,
|
|
|
|
gint len,
|
|
|
|
gpointer userData)
|
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &end);
|
|
|
|
const char* comment = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
|
|
|
|
|
|
|
|
// limit to 500 bytes in utf-8
|
|
|
|
if (strlen(comment) + len > MAX_COMMENT_LENGTH) {
|
|
|
|
g_signal_stop_emission_by_name(buffer, "insert-text");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateHintText(GtkWidget* widget, gboolean gainedFocus,
|
|
|
|
bool* hintShowing, const char* hintText)
|
|
|
|
{
|
2013-10-11 00:39:09 +04:00
|
|
|
GtkTextBuffer* buffer = nullptr;
|
2008-01-23 03:06:40 +03:00
|
|
|
if (GTK_IS_TEXT_VIEW(widget))
|
|
|
|
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
|
|
|
|
|
|
|
|
if (gainedFocus) {
|
|
|
|
if (*hintShowing) {
|
2013-10-11 00:39:09 +04:00
|
|
|
if (buffer == nullptr) { // sort of cheating
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(widget), "");
|
|
|
|
}
|
|
|
|
else { // GtkTextView
|
|
|
|
gtk_text_buffer_set_text(buffer, "", 0);
|
|
|
|
}
|
2013-10-11 00:39:09 +04:00
|
|
|
gtk_widget_modify_text(widget, GTK_STATE_NORMAL, nullptr);
|
2008-01-23 03:06:40 +03:00
|
|
|
*hintShowing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// lost focus
|
2013-10-11 00:39:09 +04:00
|
|
|
const char* text = nullptr;
|
|
|
|
if (buffer == nullptr) {
|
2008-01-23 03:06:40 +03:00
|
|
|
text = gtk_entry_get_text(GTK_ENTRY(widget));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GtkTextIter start, end;
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &end);
|
|
|
|
text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
|
|
|
|
}
|
|
|
|
|
2013-10-11 00:39:09 +04:00
|
|
|
if (text == nullptr || text[0] == '\0') {
|
2008-01-23 03:06:40 +03:00
|
|
|
*hintShowing = true;
|
|
|
|
|
2013-10-11 00:39:09 +04:00
|
|
|
if (buffer == nullptr) {
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(widget), hintText);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gtk_text_buffer_set_text(buffer, hintText, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_modify_text(widget, GTK_STATE_NORMAL,
|
|
|
|
>k_widget_get_style(widget)->text[GTK_STATE_INSENSITIVE]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean CommentFocusChange(GtkWidget* widget, GdkEventFocus* event,
|
|
|
|
gpointer userData)
|
|
|
|
{
|
|
|
|
UpdateHintText(widget, event->in, &gCommentFieldHint,
|
|
|
|
gStrings[ST_COMMENTGRAYTEXT].c_str());
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
static void UpdateEmail()
|
|
|
|
{
|
2008-03-17 17:21:47 +03:00
|
|
|
const char* email = gtk_entry_get_text(GTK_ENTRY(gEmailEntry));
|
2007-07-25 05:06:08 +04:00
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck))) {
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_set_sensitive(gEmailEntry, TRUE);
|
2007-07-25 05:06:08 +04:00
|
|
|
} else {
|
2008-03-17 17:21:47 +03:00
|
|
|
email = "";
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_set_sensitive(gEmailEntry, FALSE);
|
2007-07-25 05:06:08 +04:00
|
|
|
}
|
2008-03-17 17:21:47 +03:00
|
|
|
if (email[0] == '\0' || gEmailFieldHint)
|
|
|
|
gQueryParameters.erase("Email");
|
|
|
|
else
|
|
|
|
gQueryParameters["Email"] = email;
|
2007-07-25 05:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EmailMeClicked(GtkButton* sender, gpointer userData)
|
|
|
|
{
|
|
|
|
UpdateEmail();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EmailChanged(GtkEditable* editable, gpointer userData)
|
|
|
|
{
|
|
|
|
UpdateEmail();
|
2008-01-23 03:06:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean EmailFocusChange(GtkWidget* widget, GdkEventFocus* event,
|
|
|
|
gpointer userData)
|
|
|
|
{
|
|
|
|
UpdateHintText(widget, event->in, &gEmailFieldHint,
|
|
|
|
gStrings[ST_EMAILGRAYTEXT].c_str());
|
|
|
|
|
|
|
|
return FALSE;
|
2007-07-25 05:06:08 +04:00
|
|
|
}
|
|
|
|
|
2007-08-30 18:55:21 +04:00
|
|
|
typedef struct _GnomeProgram GnomeProgram;
|
|
|
|
typedef struct _GnomeModuleInfo GnomeModuleInfo;
|
|
|
|
typedef GnomeProgram * (*_gnome_program_init_fn)(const char *, const char *,
|
|
|
|
const GnomeModuleInfo *, int,
|
|
|
|
char **, const char *, ...);
|
|
|
|
typedef const GnomeModuleInfo * (*_libgnomeui_module_info_get_fn)();
|
|
|
|
|
2010-04-07 21:06:17 +04:00
|
|
|
void TryInitGnome()
|
2007-08-30 18:55:21 +04:00
|
|
|
{
|
|
|
|
gnomeLib = dlopen("libgnome-2.so.0", RTLD_LAZY);
|
|
|
|
if (!gnomeLib)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gnomeuiLib = dlopen("libgnomeui-2.so.0", RTLD_LAZY);
|
|
|
|
if (!gnomeuiLib)
|
|
|
|
return;
|
2007-09-26 22:35:21 +04:00
|
|
|
|
2007-08-30 18:55:21 +04:00
|
|
|
_gnome_program_init_fn gnome_program_init =
|
2007-08-31 09:07:26 +04:00
|
|
|
(_gnome_program_init_fn)(dlsym(gnomeLib, "gnome_program_init"));
|
2007-08-30 18:55:21 +04:00
|
|
|
_libgnomeui_module_info_get_fn libgnomeui_module_info_get =
|
2007-08-31 09:07:26 +04:00
|
|
|
(_libgnomeui_module_info_get_fn)(dlsym(gnomeuiLib, "libgnomeui_module_info_get"));
|
2007-08-30 18:55:21 +04:00
|
|
|
|
|
|
|
if (gnome_program_init && libgnomeui_module_info_get) {
|
|
|
|
gnome_program_init("crashreporter", "1.0", libgnomeui_module_info_get(),
|
2013-10-11 00:39:09 +04:00
|
|
|
gArgc, gArgv, nullptr);
|
2007-08-30 18:55:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
/* === Crashreporter UI Functions === */
|
|
|
|
|
2010-04-07 21:06:17 +04:00
|
|
|
/*
|
|
|
|
* Anything not listed here is in crashreporter_gtk_common.cpp:
|
|
|
|
* UIInit
|
|
|
|
* UIShowDefaultUI
|
|
|
|
* UIError_impl
|
|
|
|
* UIGetIniPath
|
|
|
|
* UIGetSettingsPath
|
|
|
|
* UIEnsurePathExists
|
|
|
|
* UIFileExists
|
|
|
|
* UIMoveFile
|
|
|
|
* UIDeleteFile
|
|
|
|
* UIOpenRead
|
|
|
|
* UIOpenWrite
|
|
|
|
*/
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2007-07-25 05:06:04 +04:00
|
|
|
void UIShutdown()
|
|
|
|
{
|
2007-08-30 18:55:21 +04:00
|
|
|
if (gnomeuiLib)
|
|
|
|
dlclose(gnomeuiLib);
|
2009-09-28 02:34:39 +04:00
|
|
|
// Don't dlclose gnomeLib as libgnomevfs and libORBit-2 use atexit().
|
2007-07-25 05:06:04 +04:00
|
|
|
}
|
|
|
|
|
2008-01-25 14:24:02 +03:00
|
|
|
bool UIShowCrashUI(const string& dumpfile,
|
2007-07-25 05:06:04 +04:00
|
|
|
const StringTable& queryParameters,
|
2007-07-25 05:06:11 +04:00
|
|
|
const string& sendURL,
|
|
|
|
const vector<string>& restartArgs)
|
2007-07-25 05:06:04 +04:00
|
|
|
{
|
2007-07-25 05:06:08 +04:00
|
|
|
gDumpFile = dumpfile;
|
|
|
|
gQueryParameters = queryParameters;
|
|
|
|
gSendURL = sendURL;
|
|
|
|
gRestartArgs = restartArgs;
|
2007-11-29 20:35:44 +03:00
|
|
|
if (gQueryParameters.find("URL") != gQueryParameters.end())
|
|
|
|
gURLParameter = gQueryParameters["URL"];
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
gWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(gWindow),
|
|
|
|
gStrings[ST_CRASHREPORTERTITLE].c_str());
|
|
|
|
gtk_window_set_resizable(GTK_WINDOW(gWindow), FALSE);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_window_set_position(GTK_WINDOW(gWindow), GTK_WIN_POS_CENTER);
|
2007-07-25 05:06:08 +04:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(gWindow), 12);
|
|
|
|
g_signal_connect(gWindow, "delete-event", G_CALLBACK(WindowDeleted), 0);
|
2014-01-16 17:44:45 +04:00
|
|
|
g_signal_connect(gWindow, "key_press_event", G_CALLBACK(check_escape), nullptr);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
GtkWidget* vbox = gtk_vbox_new(FALSE, 6);
|
|
|
|
gtk_container_add(GTK_CONTAINER(gWindow), vbox);
|
|
|
|
|
|
|
|
GtkWidget* titleLabel = gtk_label_new("");
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), titleLabel, FALSE, FALSE, 0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(titleLabel), 0, 0.5);
|
|
|
|
char* markup = g_strdup_printf("<b>%s</b>",
|
|
|
|
gStrings[ST_CRASHREPORTERHEADER].c_str());
|
|
|
|
gtk_label_set_markup(GTK_LABEL(titleLabel), markup);
|
|
|
|
g_free(markup);
|
|
|
|
|
|
|
|
GtkWidget* descriptionLabel =
|
|
|
|
gtk_label_new(gStrings[ST_CRASHREPORTERDESCRIPTION].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), descriptionLabel, TRUE, TRUE, 0);
|
|
|
|
// force the label to line wrap
|
|
|
|
gtk_widget_set_size_request(descriptionLabel, 400, -1);
|
|
|
|
gtk_label_set_line_wrap(GTK_LABEL(descriptionLabel), TRUE);
|
|
|
|
gtk_label_set_selectable(GTK_LABEL(descriptionLabel), TRUE);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(descriptionLabel), 0, 0.5);
|
|
|
|
|
|
|
|
// this is honestly how they suggest you indent a section
|
|
|
|
GtkWidget* indentBox = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), indentBox, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(indentBox), gtk_label_new(""), FALSE, FALSE, 6);
|
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
GtkWidget* innerVBox1 = gtk_vbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(indentBox), innerVBox1, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
gSubmitReportCheck =
|
|
|
|
gtk_check_button_new_with_label(gStrings[ST_CHECKSUBMIT].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(innerVBox1), gSubmitReportCheck, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect(gSubmitReportCheck, "clicked",
|
|
|
|
G_CALLBACK(SubmitReportChecked), 0);
|
|
|
|
|
|
|
|
// indent again, below the "submit report" checkbox
|
|
|
|
GtkWidget* indentBox2 = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(innerVBox1), indentBox2, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(indentBox2), gtk_label_new(""), FALSE, FALSE, 6);
|
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
GtkWidget* innerVBox = gtk_vbox_new(FALSE, 0);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_box_pack_start(GTK_BOX(indentBox2), innerVBox, TRUE, TRUE, 0);
|
|
|
|
gtk_box_set_spacing(GTK_BOX(innerVBox), 6);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
GtkWidget* viewReportButtonBox = gtk_hbutton_box_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(innerVBox), viewReportButtonBox, FALSE, FALSE, 0);
|
|
|
|
gtk_box_set_spacing(GTK_BOX(viewReportButtonBox), 6);
|
|
|
|
gtk_button_box_set_layout(GTK_BUTTON_BOX(viewReportButtonBox), GTK_BUTTONBOX_START);
|
|
|
|
|
|
|
|
gViewReportButton =
|
|
|
|
gtk_button_new_with_label(gStrings[ST_VIEWREPORT].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(viewReportButtonBox), gViewReportButton, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect(gViewReportButton, "clicked", G_CALLBACK(ViewReportClicked), 0);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
GtkWidget* scrolled = gtk_scrolled_window_new(0, 0);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_container_add(GTK_CONTAINER(innerVBox), scrolled);
|
2007-07-25 05:06:08 +04:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
|
2011-02-14 20:20:02 +03:00
|
|
|
gCommentTextLabel = gtk_label_new(gStrings[ST_COMMENTGRAYTEXT].c_str());
|
2008-01-23 03:06:40 +03:00
|
|
|
gCommentText = gtk_text_view_new();
|
2011-02-14 20:20:02 +03:00
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(gCommentTextLabel), gCommentText);
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(gCommentText), FALSE);
|
|
|
|
g_signal_connect(gCommentText, "focus-in-event", G_CALLBACK(CommentFocusChange), 0);
|
|
|
|
g_signal_connect(gCommentText, "focus-out-event", G_CALLBACK(CommentFocusChange), 0);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
GtkTextBuffer* commentBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gCommentText));
|
|
|
|
g_signal_connect(commentBuffer, "changed", G_CALLBACK(CommentChanged), 0);
|
|
|
|
g_signal_connect(commentBuffer, "insert-text", G_CALLBACK(CommentInsert), 0);
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(scrolled), gCommentText);
|
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gCommentText),
|
|
|
|
GTK_WRAP_WORD);
|
|
|
|
gtk_widget_set_size_request(GTK_WIDGET(gCommentText), -1, 100);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2007-11-29 20:35:44 +03:00
|
|
|
if (gQueryParameters.find("URL") != gQueryParameters.end()) {
|
|
|
|
gIncludeURLCheck =
|
|
|
|
gtk_check_button_new_with_label(gStrings[ST_CHECKURL].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(innerVBox), gIncludeURLCheck, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect(gIncludeURLCheck, "clicked", G_CALLBACK(IncludeURLClicked), 0);
|
|
|
|
// on by default
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gIncludeURLCheck), TRUE);
|
|
|
|
}
|
|
|
|
|
2007-07-25 05:06:08 +04:00
|
|
|
gEmailMeCheck =
|
|
|
|
gtk_check_button_new_with_label(gStrings[ST_CHECKEMAIL].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(innerVBox), gEmailMeCheck, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect(gEmailMeCheck, "clicked", G_CALLBACK(EmailMeClicked), 0);
|
|
|
|
|
|
|
|
GtkWidget* emailIndentBox = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(innerVBox), emailIndentBox, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(emailIndentBox), gtk_label_new(""),
|
|
|
|
FALSE, FALSE, 9);
|
|
|
|
|
2011-02-14 20:20:02 +03:00
|
|
|
gEmailEntryLabel = gtk_label_new(gStrings[ST_EMAILGRAYTEXT].c_str());
|
2007-07-25 05:06:08 +04:00
|
|
|
gEmailEntry = gtk_entry_new();
|
2011-02-14 20:20:02 +03:00
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(gEmailEntryLabel), gEmailEntry);
|
2007-07-25 05:06:08 +04:00
|
|
|
gtk_box_pack_start(GTK_BOX(emailIndentBox), gEmailEntry, TRUE, TRUE, 0);
|
|
|
|
g_signal_connect(gEmailEntry, "changed", G_CALLBACK(EmailChanged), 0);
|
2008-01-23 03:06:40 +03:00
|
|
|
g_signal_connect(gEmailEntry, "focus-in-event", G_CALLBACK(EmailFocusChange), 0);
|
|
|
|
g_signal_connect(gEmailEntry, "focus-out-event", G_CALLBACK(EmailFocusChange), 0);
|
|
|
|
|
|
|
|
GtkWidget* progressBox = gtk_hbox_new(FALSE, 6);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), progressBox, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
// Get the throbber image from alongside the executable
|
|
|
|
char* dir = g_path_get_dirname(gArgv[0]);
|
2013-10-11 00:39:09 +04:00
|
|
|
char* path = g_build_filename(dir, "Throbber-small.gif", nullptr);
|
2008-01-23 03:06:40 +03:00
|
|
|
g_free(dir);
|
|
|
|
gThrobber = gtk_image_new_from_file(path);
|
|
|
|
gtk_box_pack_start(GTK_BOX(progressBox), gThrobber, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
gProgressLabel =
|
|
|
|
gtk_label_new(gStrings[ST_REPORTPRESUBMIT].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(progressBox), gProgressLabel, TRUE, TRUE, 0);
|
|
|
|
// force the label to line wrap
|
|
|
|
gtk_widget_set_size_request(gProgressLabel, 400, -1);
|
|
|
|
gtk_label_set_line_wrap(GTK_LABEL(gProgressLabel), TRUE);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
GtkWidget* buttonBox = gtk_hbutton_box_new();
|
|
|
|
gtk_box_pack_end(GTK_BOX(vbox), buttonBox, FALSE, FALSE, 0);
|
|
|
|
gtk_box_set_spacing(GTK_BOX(buttonBox), 6);
|
|
|
|
gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
|
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
gCloseButton =
|
|
|
|
gtk_button_new_with_label(gStrings[ST_QUIT].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(buttonBox), gCloseButton, FALSE, FALSE, 0);
|
2013-11-12 07:01:41 +04:00
|
|
|
gtk_widget_set_can_default(gCloseButton, TRUE);
|
2008-01-23 03:06:40 +03:00
|
|
|
g_signal_connect(gCloseButton, "clicked", G_CALLBACK(CloseClicked), 0);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
gRestartButton = 0;
|
2007-07-25 05:06:08 +04:00
|
|
|
if (restartArgs.size() > 0) {
|
2008-01-23 03:06:40 +03:00
|
|
|
gRestartButton = gtk_button_new_with_label(gStrings[ST_RESTART].c_str());
|
|
|
|
gtk_box_pack_start(GTK_BOX(buttonBox), gRestartButton, FALSE, FALSE, 0);
|
2013-11-12 07:01:41 +04:00
|
|
|
gtk_widget_set_can_default(gRestartButton, TRUE);
|
2008-01-23 03:06:40 +03:00
|
|
|
g_signal_connect(gRestartButton, "clicked", G_CALLBACK(RestartClicked), 0);
|
2007-07-25 05:06:08 +04:00
|
|
|
}
|
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_grab_focus(gSubmitReportCheck);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
2008-01-23 03:06:40 +03:00
|
|
|
gtk_widget_grab_default(gRestartButton ? gRestartButton : gCloseButton);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
LoadSettings();
|
2008-01-23 03:06:40 +03:00
|
|
|
|
|
|
|
UpdateEmail();
|
|
|
|
UpdateSubmit();
|
|
|
|
|
|
|
|
UpdateHintText(gCommentText, FALSE, &gCommentFieldHint,
|
|
|
|
gStrings[ST_COMMENTGRAYTEXT].c_str());
|
|
|
|
UpdateHintText(gEmailEntry, FALSE, &gEmailFieldHint,
|
|
|
|
gStrings[ST_EMAILGRAYTEXT].c_str());
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
gtk_widget_show_all(gWindow);
|
2008-01-23 03:06:40 +03:00
|
|
|
// stick this here to avoid the show_all above...
|
2013-11-12 07:01:41 +04:00
|
|
|
gtk_widget_hide(gThrobber);
|
2007-07-25 05:06:08 +04:00
|
|
|
|
|
|
|
gtk_main();
|
2008-01-25 14:24:02 +03:00
|
|
|
|
|
|
|
return gDidTrySend;
|
2007-07-25 05:06:04 +04:00
|
|
|
}
|