Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
progressui_gtk.cpp File Reference
#include <stdio.h>
#include <gtk/gtk.h>
#include <unistd.h>
#include "progressui.h"
#include "readstrings.h"
#include "errors.h"

Go to the source code of this file.


#define TIMER_INTERVAL   100


static gboolean UpdateDialog (gpointer data)
static gboolean OnDeleteEvent (GtkWidget *widget, GdkEvent *event, gpointer user_data)
int InitProgressUI (int *pargc, char ***pargv)
int ShowProgressUI ()
void QuitProgressUI ()
void UpdateProgressUI (float progress)


static float sProgressVal
static gboolean sQuit = FALSE
static gboolean sEnableUI
static guint sTimerID
static GtkWidget * sWin
static GtkWidget * sLabel
static GtkWidget * sProgressBar
static const char * sProgramPath

Define Documentation

Definition at line 46 of file progressui_gtk.cpp.

Function Documentation

int InitProgressUI ( int pargc,
char ***  pargv 

Definition at line 83 of file progressui_gtk.cpp.

  sProgramPath = (*pargv)[0];

  sEnableUI = gtk_init_check(pargc, pargv);
  return 0;
static gboolean OnDeleteEvent ( GtkWidget *  widget,
GdkEvent *  event,
gpointer  user_data 
) [static]

Definition at line 77 of file progressui_gtk.cpp.

  return TRUE;

Here is the caller graph for this function:

Definition at line 152 of file progressui_gtk.cpp.

  sQuit = TRUE;

Definition at line 92 of file progressui_gtk.cpp.

  if (!sEnableUI)
    return -1;

  // Only show the Progress UI if the process is taking significant time.
  // Here we measure significant time as taking more than one second.


  if (sQuit || sProgressVal > 50.0f)
    return 0;

  char path[PATH_MAX];
  snprintf(path, sizeof(path), "%s.ini", sProgramPath);

  StringTable strings;
  if (ReadStrings(path, &strings) != OK)
    return -1;
  sWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  if (!sWin)
    return -1;

  // GTK 2.2 seems unable to prevent our dialog from being closed when
  // the user hits the close button on the dialog.  This problem only
  // occurs when either one of the following methods are called:
  //   gtk_window_set_position
  //   gtk_window_set_type_hint
  // For this reason, we disable window decorations.
  g_signal_connect(G_OBJECT(sWin), "delete_event",
                   G_CALLBACK(OnDeleteEvent), NULL);

  gtk_window_set_title(GTK_WINDOW(sWin), strings.title);
  gtk_window_set_type_hint(GTK_WINDOW(sWin), GDK_WINDOW_TYPE_HINT_DIALOG);
  gtk_window_set_position(GTK_WINDOW(sWin), GTK_WIN_POS_CENTER_ALWAYS);
  gtk_window_set_resizable(GTK_WINDOW(sWin), FALSE);
  gtk_window_set_decorated(GTK_WINDOW(sWin), FALSE);

  GtkWidget *vbox = gtk_vbox_new(TRUE, 6);
  sLabel = gtk_label_new(;
  gtk_misc_set_alignment(GTK_MISC(sLabel), 0.0f, 0.0f);
  sProgressBar = gtk_progress_bar_new();

  gtk_box_pack_start(GTK_BOX(vbox), sLabel, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), sProgressBar, TRUE, TRUE, 0);

  sTimerID = g_timeout_add(TIMER_INTERVAL, UpdateDialog, NULL);

  gtk_container_set_border_width(GTK_CONTAINER(sWin), 10);
  gtk_container_add(GTK_CONTAINER(sWin), vbox);

  return 0;

Here is the call graph for this function:

static gboolean UpdateDialog ( gpointer  data) [static]

Definition at line 60 of file progressui_gtk.cpp.

  if (sQuit)

  float progress = sProgressVal;

                                progress / 100.0);

  return TRUE;

Here is the caller graph for this function:

void UpdateProgressUI ( float  progress)

Definition at line 159 of file progressui_gtk.cpp.

  sProgressVal = progress;  // 32-bit writes are atomic

Variable Documentation

gboolean sEnableUI [static]

Definition at line 50 of file progressui_gtk.cpp.

GtkWidget* sLabel [static]

Definition at line 54 of file progressui_gtk.cpp.

const char* sProgramPath [static]

Definition at line 57 of file progressui_gtk.cpp.

GtkWidget* sProgressBar [static]

Definition at line 55 of file progressui_gtk.cpp.

float sProgressVal [static]

Definition at line 48 of file progressui_gtk.cpp.

gboolean sQuit = FALSE [static]

Definition at line 49 of file progressui_gtk.cpp.

guint sTimerID [static]

Definition at line 51 of file progressui_gtk.cpp.

GtkWidget* sWin [static]

Definition at line 53 of file progressui_gtk.cpp.