toolkit/mozapps/update/updater/progressui_gtk.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include <stdio.h>
     8 #include <gtk/gtk.h>
     9 #include <unistd.h>
    10 #include "progressui.h"
    11 #include "readstrings.h"
    12 #include "errors.h"
    14 #define TIMER_INTERVAL 100
    16 static float    sProgressVal;  // between 0 and 100
    17 static gboolean sQuit = FALSE;
    18 static gboolean sEnableUI;
    19 static guint    sTimerID;
    21 static GtkWidget *sWin;
    22 static GtkWidget *sLabel;
    23 static GtkWidget *sProgressBar;
    25 static const char *sProgramPath;
    27 static gboolean
    28 UpdateDialog(gpointer data)
    29 {
    30   if (sQuit)
    31   {
    32     gtk_widget_hide(sWin);
    33     gtk_main_quit();
    34   }
    36   float progress = sProgressVal;
    38   gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(sProgressBar),
    39                                 progress / 100.0);
    41   return TRUE;
    42 }
    44 static gboolean
    45 OnDeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
    46 {
    47   return TRUE;
    48 }
    50 int
    51 InitProgressUI(int *pargc, char ***pargv)
    52 {
    53   sProgramPath = (*pargv)[0];
    55   sEnableUI = gtk_init_check(pargc, pargv);
    56   return 0;
    57 }
    59 int
    60 ShowProgressUI()
    61 {
    62   if (!sEnableUI)
    63     return -1;
    65   // Only show the Progress UI if the process is taking a significant amount of
    66   // time where a significant amount of time is defined as .5 seconds after
    67   // ShowProgressUI is called sProgress is less than 70.
    68   usleep(500000);
    70   if (sQuit || sProgressVal > 70.0f)
    71     return 0;
    73   char ini_path[PATH_MAX];
    74   snprintf(ini_path, sizeof(ini_path), "%s.ini", sProgramPath);
    76   StringTable strings;
    77   if (ReadStrings(ini_path, &strings) != OK)
    78     return -1;
    80   sWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    81   if (!sWin)
    82     return -1;
    84   static GdkPixbuf *pixbuf;
    85   char icon_path[PATH_MAX];
    86   snprintf(icon_path, sizeof(icon_path), "%s.png", sProgramPath);
    88   g_signal_connect(G_OBJECT(sWin), "delete_event",
    89                    G_CALLBACK(OnDeleteEvent), nullptr);
    91   gtk_window_set_title(GTK_WINDOW(sWin), strings.title);
    92   gtk_window_set_type_hint(GTK_WINDOW(sWin), GDK_WINDOW_TYPE_HINT_DIALOG);
    93   gtk_window_set_position(GTK_WINDOW(sWin), GTK_WIN_POS_CENTER_ALWAYS);
    94   gtk_window_set_resizable(GTK_WINDOW(sWin), FALSE);
    95   gtk_window_set_decorated(GTK_WINDOW(sWin), TRUE);
    96   gtk_window_set_deletable(GTK_WINDOW(sWin),FALSE);
    97   pixbuf = gdk_pixbuf_new_from_file (icon_path, nullptr);
    98   gtk_window_set_icon(GTK_WINDOW(sWin), pixbuf);
    99   g_object_unref(pixbuf);
   101   GtkWidget *vbox = gtk_vbox_new(TRUE, 6);
   102   sLabel = gtk_label_new(strings.info);
   103   gtk_misc_set_alignment(GTK_MISC(sLabel), 0.0f, 0.0f);
   104   sProgressBar = gtk_progress_bar_new();
   106   gtk_box_pack_start(GTK_BOX(vbox), sLabel, FALSE, FALSE, 0);
   107   gtk_box_pack_start(GTK_BOX(vbox), sProgressBar, TRUE, TRUE, 0);
   109   sTimerID = g_timeout_add(TIMER_INTERVAL, UpdateDialog, nullptr);
   111   gtk_container_set_border_width(GTK_CONTAINER(sWin), 10);
   112   gtk_container_add(GTK_CONTAINER(sWin), vbox);
   113   gtk_widget_show_all(sWin);
   115   gtk_main();
   116   return 0;
   117 }
   119 // Called on a background thread
   120 void
   121 QuitProgressUI()
   122 {
   123   sQuit = TRUE;
   124 }
   126 // Called on a background thread
   127 void
   128 UpdateProgressUI(float progress)
   129 {
   130   sProgressVal = progress;  // 32-bit writes are atomic
   131 }

mercurial