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)
11 #include "progressui.h"
12 #include "readstrings.h"
15 #include "progressui_gtk_icon.h"
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
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
;
36 UpdateDialog(gpointer
/*data*/)
40 gtk_widget_hide(sWin
);
44 float progress
= sProgressVal
;
46 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(sProgressBar
),
53 OnDeleteEvent(GtkWidget
* /*widget*/, GdkEvent
* /*event*/, gpointer
/*user_data*/)
59 InitProgressUI(int *pargc
, char ***pargv
)
61 sProgramPath
= (*pargv
)[0];
63 sEnableUI
= gtk_init_check(pargc
, pargv
);
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.
78 if (sQuit
|| sProgressVal
> 70.0f
)
81 char ini_path
[PATH_MAX
];
82 snprintf(ini_path
, sizeof(ini_path
), "%s.ini", sProgramPath
);
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
);
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
);
128 // Called on a background thread
135 // Called on a background thread
137 UpdateProgressUI(float progress
)
139 sProgressVal
= progress
; // 32-bit writes are atomic
143 #pragma GCC diagnostic pop
146 #endif // defined(UNIX) || defined(MACOSX)