~ubuntu-branches/ubuntu/oneiric/notecase/oneiric

« back to all changes in this revision

Viewing changes to src/gui/ProgressDlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Soyez
  • Date: 2008-11-10 11:29:57 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20081110112957-9uu6p24w7i0c7ib2
Tags: 1.9.7-0ubuntu1
* New Upstream Release
* Updated Standards-Version to 3.8.0, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
static GtkWidget *g_progress1 = NULL;
26
26
bool   g_bStartProgress = true;
27
27
 
 
28
int ProgressDlg::m_nCurrentSize = 0;
 
29
int ProgressDlg::m_nTotalSize = 0;
 
30
bool ProgressDlg::m_bCanceled = false;
 
31
 
28
32
static int progress_timer(gpointer data);
29
33
static int progress_start_timer(gpointer data);
 
34
static void on_abort_clicked(GtkButton *button, gpointer user_data);
30
35
 
31
 
ProgressDlg::ProgressDlg(int nWaitMs, const char *szTitle, GtkWidget *pParent)
 
36
ProgressDlg::ProgressDlg(int nWaitMs, const char *szTitle, GtkWidget *pParent, bool bCancelBtn)
32
37
{
33
38
        if(szTitle && strlen(szTitle) > 0)
34
39
                m_strTitle = szTitle;
35
40
 
36
41
        m_nProgressTimer = 0;
 
42
        m_nTotalSize    = -1;
 
43
        m_nCurrentSize  = -1;
37
44
 
38
45
        m_pDialog = NULL;
39
46
        m_pParent = pParent;
 
47
        m_bCancelBtn = bCancelBtn;
40
48
 
41
49
        //start timer
42
50
        g_bStartProgress = true;
48
56
        Close();
49
57
}
50
58
 
 
59
void ProgressDlg::SetTotalSize(int nSize)
 
60
{
 
61
        m_nTotalSize = nSize;
 
62
        m_nCurrentSize = 0;
 
63
}
 
64
        
 
65
void ProgressDlg::SetCurrentSize(int nSize)
 
66
{
 
67
        m_nCurrentSize = nSize;
 
68
}
 
69
 
51
70
void ProgressDlg::DoCreateWindow()
52
71
{
53
72
        //show wait dialog
91
110
                gtk_widget_show (g_progress1);
92
111
                gtk_box_pack_start (GTK_BOX (vbox1), g_progress1, FALSE, FALSE, 3);
93
112
                
 
113
                if(m_bCancelBtn)
 
114
                {
 
115
                        GtkWidget *btnabort = gtk_button_new_with_mnemonic (_("Abort"));
 
116
                        gtk_widget_show (btnabort);
 
117
                        gtk_box_pack_start (GTK_BOX (vbox1), btnabort, FALSE, FALSE, 3);
 
118
                        GTK_WIDGET_SET_FLAGS (btnabort, GTK_CAN_DEFAULT);
 
119
                        g_signal_connect(btnabort, "clicked", G_CALLBACK (on_abort_clicked), this);
 
120
                }
 
121
 
94
122
                gtk_widget_show (msgbox);
95
123
                gtk_widget_realize(msgbox);
96
124
                m_pDialog = msgbox;
126
154
        }
127
155
}
128
156
 
 
157
void ProgressDlg::OnCancel()
 
158
{
 
159
        m_bCanceled = true;
 
160
        Close();
 
161
}
 
162
 
129
163
gboolean progress_start_timer(gpointer data)
130
164
{
131
165
        if(g_bStartProgress)
154
188
        else
155
189
        {
156
190
                //ensure progress dialog is visible and pulse the progress
157
 
                gtk_widget_show(g_wndProgressDlg);
158
 
                if(g_progress1)
159
 
                        gtk_progress_bar_pulse(GTK_PROGRESS_BAR(g_progress1));
 
191
                if(g_wndProgressDlg) gtk_widget_show(g_wndProgressDlg);
 
192
                if(g_progress1){
 
193
                        if(ProgressDlg::m_nTotalSize > 0)       //TOFIX what if two loads at te same time ? not static!??
 
194
                        {
 
195
                                gtk_progress_set_percentage(GTK_PROGRESS(g_progress1), ((double)ProgressDlg::m_nCurrentSize)/ProgressDlg::m_nTotalSize);
 
196
                        }
 
197
                        else
 
198
                                gtk_progress_bar_pulse(GTK_PROGRESS_BAR(g_progress1));
 
199
                }
160
200
        }
161
201
        return TRUE;
162
202
}
 
203
 
 
204
void on_abort_clicked (GtkButton *button, gpointer user_data)
 
205
{
 
206
        ProgressDlg *pDlg = (ProgressDlg *)user_data;
 
207
        pDlg->OnCancel();
 
208
}