nss: upgrade to release 3.73
[LibreOffice.git] / onlineupdate / source / update / updater / progressui_gtk.cxx
blob7c3bcfcd8b2d4b7c84cd138e66ea45049049fa9c
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 #if defined(UNIX) || defined(MACOSX)
8 #include <stdio.h>
9 #include <gtk/gtk.h>
10 #include <unistd.h>
11 #include "progressui.h"
12 #include "readstrings.h"
13 #include "errors.h"
14 #include <string.h>
15 #include "progressui_gtk_icon.h"
17 #ifdef __GNUC__
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20 #endif
22 #define TIMER_INTERVAL 100
24 static float sProgressVal; // between 0 and 100
25 static gboolean sQuit = FALSE;
26 static gboolean sEnableUI;
27 static guint sTimerID;
29 static GtkWidget *sWin;
30 static GtkWidget *sLabel;
31 static GtkWidget *sProgressBar;
33 static const char *sProgramPath;
35 static gboolean
36 UpdateDialog(gpointer /*data*/)
38 if (sQuit)
40 gtk_widget_hide(sWin);
41 gtk_main_quit();
44 float progress = sProgressVal;
46 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(sProgressBar),
47 progress / 100.0);
49 return TRUE;
52 static gboolean
53 OnDeleteEvent(GtkWidget * /*widget*/, GdkEvent * /*event*/, gpointer /*user_data*/)
55 return TRUE;
58 int
59 InitProgressUI(int *pargc, char ***pargv)
61 sProgramPath = (*pargv)[0];
63 sEnableUI = gtk_init_check(pargc, pargv);
64 return 0;
67 int
68 ShowProgressUI()
70 if (!sEnableUI)
71 return -1;
73 // Only show the Progress UI if the process is taking a significant amount of
74 // time where a significant amount of time is defined as .5 seconds after
75 // ShowProgressUI is called sProgress is less than 70.
76 usleep(500000);
78 if (sQuit || sProgressVal > 70.0f)
79 return 0;
81 char ini_path[PATH_MAX];
82 snprintf(ini_path, sizeof(ini_path), "%s.ini", sProgramPath);
84 StringTable strings;
85 if (ReadStrings(ini_path, &strings) != OK)
87 strcpy(strings.title, "LibreOffice Update");
88 strcpy(strings.info, "Please wait while we update your installation.");
91 sWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
92 if (!sWin)
93 return -1;
95 static GdkPixbuf *pixbuf;
97 g_signal_connect(G_OBJECT(sWin), "delete_event",
98 G_CALLBACK(OnDeleteEvent), nullptr);
100 gtk_window_set_title(GTK_WINDOW(sWin), strings.title);
101 gtk_window_set_type_hint(GTK_WINDOW(sWin), GDK_WINDOW_TYPE_HINT_DIALOG);
102 gtk_window_set_position(GTK_WINDOW(sWin), GTK_WIN_POS_CENTER_ALWAYS);
103 gtk_window_set_resizable(GTK_WINDOW(sWin), FALSE);
104 gtk_window_set_decorated(GTK_WINDOW(sWin), TRUE);
105 gtk_window_set_deletable(GTK_WINDOW(sWin),FALSE);
106 pixbuf = gdk_pixbuf_new_from_xpm_data (icon_data);
107 gtk_window_set_icon(GTK_WINDOW(sWin), pixbuf);
108 g_object_unref(pixbuf);
110 GtkWidget *vbox = gtk_vbox_new(TRUE, 6);
111 sLabel = gtk_label_new(strings.info);
112 gtk_misc_set_alignment(GTK_MISC(sLabel), 0.0f, 0.0f);
113 sProgressBar = gtk_progress_bar_new();
115 gtk_box_pack_start(GTK_BOX(vbox), sLabel, FALSE, FALSE, 0);
116 gtk_box_pack_start(GTK_BOX(vbox), sProgressBar, TRUE, TRUE, 0);
118 sTimerID = g_timeout_add(TIMER_INTERVAL, UpdateDialog, nullptr);
120 gtk_container_set_border_width(GTK_CONTAINER(sWin), 10);
121 gtk_container_add(GTK_CONTAINER(sWin), vbox);
122 gtk_widget_show_all(sWin);
124 gtk_main();
125 return 0;
128 // Called on a background thread
129 void
130 QuitProgressUI()
132 sQuit = TRUE;
135 // Called on a background thread
136 void
137 UpdateProgressUI(float progress)
139 sProgressVal = progress; // 32-bit writes are atomic
142 #ifdef __GNUC__
143 #pragma GCC diagnostic pop
144 #endif
146 #endif // defined(UNIX) || defined(MACOSX)