Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ServiceStatus.cs « GUI « Duplicati - github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4b8aefd7b4acfa35d048263cdcaca784e95ed55a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
#region Disclaimer / License
// Copyright (C) 2011, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
// 
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Duplicati.Datamodel;
using Duplicati.Library.Utility;

namespace Duplicati.GUI
{
    public partial class ServiceStatus : Form
    {
        private enum QuickActionType
        {
            None,
            Pause,
            Resume,
            Pause5Min,
            Pause10Min,
            Pause15Min,
            Pause30Min,
            Pause60Min,
            StopBackup,
            ThrottleDialog,
            QuitDuplicati
        }

        public ServiceStatus()
        {
            InitializeComponent();

            if (Library.Utility.Utility.IsClientLinux || Program.TraylessMode)
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;

            if (Program.TraylessMode)
            {
                this.StartPosition = FormStartPosition.CenterScreen;
                this.MinimizeBox = true;
                this.ShowInTaskbar = true;
                this.ShowIcon = true;
            }

            imageList.Images.Clear();
            imageList.Images.Add(DuplicatiOutputParser.OKStatus, Properties.Resources.OKStatusIcon);
            imageList.Images.Add(DuplicatiOutputParser.WarningStatus, Properties.Resources.WarningStatusIcon);
            imageList.Images.Add(DuplicatiOutputParser.ErrorStatus, Properties.Resources.ErrorStatusIcon);
            imageList.Images.Add(DuplicatiOutputParser.PartialStatus, Properties.Resources.PartialStatusIcon);
            imageList.Images.Add(DuplicatiOutputParser.InterruptedStatus, Properties.Resources.InterruptedStatusIcon);
            imageList.Images.Add(DuplicatiOutputParser.NoChangedFiles, Properties.Resources.EmptyBackupStatusIcon);

            this.Text = String.Format(Strings.ServiceStatus.DialogTitle, License.VersionNumbers.Version);

            string indent = "  ";
            QuickActions.Items.Clear();
            QuickActions.Items.AddRange(
                new object[] {
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(Strings.ServiceStatus.SelectQuickAction, QuickActionType.None),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(Strings.ServiceStatus.QuickActionPause, QuickActionType.Pause),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(indent + Strings.ServiceStatus.QuickActionPause5, QuickActionType.Pause5Min),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(indent + Strings.ServiceStatus.QuickActionPause10, QuickActionType.Pause10Min),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(indent + Strings.ServiceStatus.QuickActionPause15, QuickActionType.Pause15Min),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(indent + Strings.ServiceStatus.QuickActionPause30, QuickActionType.Pause30Min),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(indent + Strings.ServiceStatus.QuickActionPause60, QuickActionType.Pause60Min),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(Strings.ServiceStatus.QuickActionThrottle, QuickActionType.ThrottleDialog),
                    new Library.Utility.ComboBoxItemPair<QuickActionType>(Strings.ServiceStatus.QuickActionExit, QuickActionType.QuitDuplicati),
                });
            QuickActions.SelectedIndex = 0;
        }

        private void ServiceStatus_Load(object sender, EventArgs e)
        {
            this.FormClosed += new FormClosedEventHandler(ServiceStatus_FormClosed);
            Program.WorkThread.StartingWork += new EventHandler(WorkThread_StartingWork);
            Program.WorkThread.CompletedWork += new EventHandler(WorkThread_CompletedWork);
            Program.WorkThread.WorkQueueChanged += new EventHandler(WorkThread_WorkQueueChanged);
            Program.Scheduler.NewSchedule += new EventHandler(Scheduler_NewSchedule);
            Program.Runner.ProgressEvent += new DuplicatiRunner.ProgressEventDelegate(Runner_DuplicatiProgress);
            Program.LiveControl.StateChanged += new EventHandler(LiveControl_StateChanged);
            Program.DataConnection.AfterDataConnection += new System.Data.LightDatamodel.DataConnectionEventHandler(DataConnection_AfterDataConnection);

            LiveControl_StateChanged(null, null);

            WorkThread_WorkQueueChanged(null, null);
            Scheduler_NewSchedule(null, null);
            BuildRecent();
            PlaceAtBottom();

            if (Program.WorkThread.CurrentTask != null)
                Program.Runner.ReinvokeLastProgressEvent();            
        }

        private delegate void EmptyDelegate();
        private void DataConnection_AfterDataConnection(object sender, System.Data.LightDatamodel.DataActions action)
        {
            if (action != System.Data.LightDatamodel.DataActions.Fetch) 
			{
				if (Library.Utility.Utility.IsMono)
					MonoSupport.BeginInvoke (this, new EmptyDelegate(BuildRecent));
				else
                	this.BeginInvoke(new EmptyDelegate(BuildRecent));
			}
        }

        void LiveControl_StateChanged(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new EventHandler(LiveControl_StateChanged), sender, e);
                return;
            }

            stopBackupToolStripMenuItem.Enabled = Program.WorkThread.Active;
            UpdateQuickStateStop(Program.WorkThread.Active);

            SetQuickActionsPauseState();
            
            if (Program.LiveControl.State == LiveControls.LiveControlState.Paused)
            {
                pauseBackupToolStripMenuItem.Checked = true;
                pauseBackupToolStripMenuItem.Text = Strings.Common.MenuResume;
                CurrentStatus.Text = Strings.ServiceStatus.StatusPaused;
                statusImage.Image = Properties.Resources.Status_pause;
            }
            else
            {
                pauseBackupToolStripMenuItem.Checked = false;
                pauseBackupToolStripMenuItem.Text = Strings.Common.MenuPause;
                if (Program.WorkThread.CurrentTask == null)
                    WorkThread_CompletedWork(null, null);
                else
                    WorkThread_StartingWork(null, null);
            }
        }

        /// <summary>
        /// Helper function that removes the QuickState item for Pause/Resume and inserts the right one
        /// </summary>
        private void SetQuickActionsPauseState()
        {
            int index = -1;
            for(int i = 0; i < QuickActions.Items.Count; i++)
                if (QuickActions.Items[i] is ComboBoxItemPair<QuickActionType>)
                {
                    QuickActionType action = ((ComboBoxItemPair<QuickActionType>)QuickActions.Items[i]).Value;
                    if (action == QuickActionType.Pause || action == QuickActionType.Resume)
                    {
                        //If it is already correct, return now
                        if (action == QuickActionType.Resume && Program.LiveControl.State == LiveControls.LiveControlState.Paused)
                            return;

                        if (action == QuickActionType.Pause && Program.LiveControl.State == LiveControls.LiveControlState.Running)
                            return;

                        index = i;
                        break;
                    }
                }

            ComboBoxItemPair<QuickActionType> newitem;
            if (Program.LiveControl.State == LiveControls.LiveControlState.Paused)
                newitem = new ComboBoxItemPair<QuickActionType>(Strings.ServiceStatus.QuickActionResume, QuickActionType.Resume);
            else
                newitem = new ComboBoxItemPair<QuickActionType>(Strings.ServiceStatus.QuickActionPause, QuickActionType.Pause);

            QuickActions.Items.RemoveAt(index);
            QuickActions.Items.Insert(index, newitem);
        }

        /// <summary>
        /// Updates the QuickState combo and removes or inserts the stop backup item
        /// </summary>
        private void UpdateQuickStateStop(bool enabled)
        {
            int index = -1;
            for(int i = 0; i < QuickActions.Items.Count; i++)
                if (QuickActions.Items[i] is ComboBoxItemPair<QuickActionType>)
                {
                    QuickActionType action = ((ComboBoxItemPair<QuickActionType>)QuickActions.Items[i]).Value;
                    if (action == QuickActionType.StopBackup)
                    {
                        index = i;
                        break;
                    }
                }

            if (index == -1 && enabled)
            {
                QuickActions.Items.Insert(QuickActions.Items.Count - 3, new ComboBoxItemPair<QuickActionType>(Strings.ServiceStatus.QuickActionStop, QuickActionType.StopBackup));
            }
            else if (index != -1 && !enabled)
            {
                QuickActions.Items.RemoveAt(index);
            }
        }

        void Runner_DuplicatiProgress(Duplicati.Library.Main.DuplicatiOperation operation, DuplicatiRunner.RunnerState state, string message, string submessage, int progress, int subprogress)
        {
            if (this.InvokeRequired)
                this.Invoke(new DuplicatiRunner.ProgressEventDelegate(Runner_DuplicatiProgress), operation, state, message, submessage, progress, subprogress);
            else
            {
                WorkProgressbar.Visible = ProgressMessage.Visible = state != DuplicatiRunner.RunnerState.Stopped;
                WorkProgressbar.Style = progress < 0 ? ProgressBarStyle.Marquee : ProgressBarStyle.Blocks;
                WorkProgressbar.Value = Math.Max(Math.Min(WorkProgressbar.Maximum, progress), WorkProgressbar.Minimum);
                ProgressMessage.Text = message;
                toolTip1.SetToolTip(SubProgressBar, submessage);

                SubProgressBar.Value = Math.Max(Math.Min(SubProgressBar.Maximum, subprogress), SubProgressBar.Minimum);
                if (!SubProgressBar.Visible && subprogress >= 0)
                    ProgressMessage_TextChanged(null, null);
                SubProgressBar.Visible = subprogress >= 0;

                toolTip1.SetToolTip(ProgressMessage, ProgressMessage.Text);
                toolTip1.SetToolTip(WorkProgressbar, ProgressMessage.Text);
            }
        }

        void Scheduler_NewSchedule(object sender, EventArgs e)
        {
            try
            {
                if (this.InvokeRequired)
                    this.Invoke(new EventHandler(Scheduler_NewSchedule), sender, e);
                else
                    RebuildScheduled();
            }
            catch 
            {
                //TODO: This happens occasionally when the user closes the dialog because, the form is disposed before the event is detached
                //I've only seen it happen once
            }
        }

        private void RebuildScheduled()
        {
            lock (Program.MainLock)
                try
                {
                    pendingView.BeginUpdate();
                    pendingView.Items.Clear();
                    foreach (IDuplicityTask t in Program.WorkThread.CurrentTasks)
                    {
                        ListViewItem lvi = pendingView.Items.Add(Strings.ServiceStatus.BackupImmediate);
                        lvi.SubItems.Add(t.Schedule.Name == null ? "" : t.Schedule.Name);
                        lvi.Tag = t; //Note: not a schedule object!
                    }

                    foreach (Schedule s in Program.Scheduler.Schedule)
                    {
                        ListViewItem lvi = pendingView.Items.Add(s.NextScheduledTime.ToString("g"));
                        lvi.SubItems.Add(s.Name);
                        lvi.Tag = s;
                    }
                }
                finally
                {
                    pendingView.EndUpdate();
                }

        }

        void ServiceStatus_FormClosed(object sender, FormClosedEventArgs e)
        {
            Program.DataConnection.AfterDataConnection -= new System.Data.LightDatamodel.DataConnectionEventHandler(DataConnection_AfterDataConnection);
            Program.WorkThread.StartingWork -= new EventHandler(WorkThread_StartingWork);
            Program.WorkThread.CompletedWork -= new EventHandler(WorkThread_CompletedWork);
            Program.WorkThread.WorkQueueChanged -= new EventHandler(WorkThread_WorkQueueChanged);
            Program.Scheduler.NewSchedule -= new EventHandler(Scheduler_NewSchedule);
            Program.Runner.ProgressEvent -= new DuplicatiRunner.ProgressEventDelegate(Runner_DuplicatiProgress);
            Program.LiveControl.StateChanged -= new EventHandler(LiveControl_StateChanged);
        }

        void WorkThread_CompletedWork(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
                this.Invoke(new EventHandler(WorkThread_CompletedWork), sender, e);
            else
            {
                if (Program.LiveControl.State != LiveControls.LiveControlState.Paused)
                {
                    CurrentStatus.Text = Strings.ServiceStatus.StatusWaiting;
                    statusImage.Image = Properties.Resources.Status_OK;
                    BuildRecent();
                }

                stopBackupToolStripMenuItem.Enabled = false;
                UpdateQuickStateStop(false);
            }
        }

        void WorkThread_StartingWork(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
                this.Invoke(new EventHandler(WorkThread_StartingWork), sender, e);
            else
            {
                Schedule c = Program.WorkThread.CurrentTask.Schedule;
                string prefix = Program.WorkThread.CurrentTask.TaskType == DuplicityTaskType.Restore ? Strings.ServiceStatus.StatusRestore : Strings.ServiceStatus.StatusBackup;

                CurrentStatus.Text = c == null ? Strings.ServiceStatus.StatusWaiting : string.Format(prefix, c.Name);
                statusImage.Image = Properties.Resources.Status_Working;
                WorkThread_WorkQueueChanged(sender, e);
                stopBackupToolStripMenuItem.Enabled = true;
                UpdateQuickStateStop(true);
            }
        }

        void WorkThread_WorkQueueChanged(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
                this.Invoke(new EventHandler(WorkThread_WorkQueueChanged), sender, e);
            else
                RebuildScheduled();

        }

        private void PlaceAtBottom()
        {
            this.Top = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
            this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
        }

        private void BuildRecent()
        {
            Log[] logs;
            lock(Program.MainLock)
                logs = Program.DataConnection.GetObjects<Log>("EndTime > ? AND SubAction LIKE ? ORDER BY EndTime DESC", Timeparser.ParseTimeInterval(new Datamodel.ApplicationSettings(Program.DataConnection).RecentBackupDuration, DateTime.Now, true), "Primary");

            try
            {
                recentBackups.BeginUpdate();
                recentBackups.Items.Clear();
                foreach (Log l in logs)
                {
                    ListViewItem lvi = new ListViewItem(new string[] { l.EndTime.ToString("g"), l.OwnerTask == null || l.OwnerTask.Schedule == null ? "" : l.OwnerTask.Schedule.Name, l.Transfersize > 0 ? l.TransferSizeString : "" });

                    lvi.Tag = l;
                    lvi.ImageIndex = imageList.Images.ContainsKey(l.ParsedStatus) ? imageList.Images.IndexOfKey(l.ParsedStatus) : imageList.Images.IndexOfKey("Warning");
                    recentBackups.Items.Add(lvi);

                    if (!string.IsNullOrEmpty(l.ParsedMessage))
                    {
                        lvi.ToolTipText = l.ParsedMessage;
                    }
                    else
                    {
                        switch (l.ParsedStatus)
                        {
                            case DuplicatiOutputParser.OKStatus:
                                lvi.ToolTipText = Strings.ServiceStatus.BackupStatusOK;
                                break;
                            case DuplicatiOutputParser.ErrorStatus:
                                lvi.ToolTipText = Strings.ServiceStatus.BackupStatusError;
                                break;
                            case DuplicatiOutputParser.WarningStatus:
                                lvi.ToolTipText = Strings.ServiceStatus.BackupStatusWarning;
                                break;
                            case DuplicatiOutputParser.PartialStatus:
                                lvi.ToolTipText = Strings.ServiceStatus.BackupStatusPartial;
                                break;
                        }
                    }
                }
            }
            finally
            {
                recentBackups.EndUpdate();
            }
        }

        private void recentBackups_DoubleClick(object sender, EventArgs e)
        {
            if (recentBackups.SelectedItems.Count != 1)
                return;

            Log l = recentBackups.SelectedItems[0].Tag as Log;
            if (l == null)
                return;

            LogViewer dlg = new LogViewer();
            if (!string.IsNullOrEmpty(l.ParsedMessage))
                dlg.LogText.Text = l.ParsedMessage + Environment.NewLine + Environment.NewLine;
            else
                dlg.LogText.Text = "";

            //TODO: Figure out if LDM still fails here
            dlg.LogText.Text += l.Blob.StringData;

            dlg.ShowDialog(this);
        }

        private void ServiceStatus_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                e.Handled = true;
            }
        }

        private void ProgressMessage_TextChanged(object sender, EventArgs e)
        {
            int gap = ProgressMessage.Left - statusImage.Right;
            SubProgressBar.Width = Math.Max(0, (simplePanel.Width - ProgressMessage.Right) - (gap * 2));
            SubProgressBar.Left = simplePanel.Width - SubProgressBar.Width;
        }

        private void recentBackups_SelectedIndexChanged(object sender, EventArgs e)
        {
            viewFilesToolStripMenuItem.Enabled = viewLogToolStripMenuItem.Enabled = recentBackups.SelectedItems.Count == 1;
        }

        private void viewFilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (recentBackups.SelectedItems.Count != 1)
                return;

            Log l = recentBackups.SelectedItems[0].Tag as Log;
            if (l == null)
                return;

            if (DuplicatiOutputParser.NoChangedFiles.Equals(l.ParsedStatus, StringComparison.InvariantCultureIgnoreCase))
            {
                MessageBox.Show(this, Strings.ServiceStatus.NoFilesInBackupMessages, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Schedule s = l.OwnerTask.Schedule;
            DateTime time = l.EndTime; //Not the exact time to use, but close enough unless there were multiple backups running at the same time

            ListBackupFiles dlg = new ListBackupFiles();
            dlg.ShowList(this, s, time);
        }

        private void viewLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            recentBackups_DoubleClick(sender, e);
        }

        private void pauseBackupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Program.LiveControl.State == LiveControls.LiveControlState.Running)
                Program.LiveControl.Pause();
            else
                Program.LiveControl.Resume();
        }

        private void stopBackupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.Runner.Stop(CloseReason.UserClosing);
        }

        private void statusImage_Click(object sender, EventArgs e)
        {
            backupTasks.Show(Cursor.Position.X, Cursor.Position.Y);
        }

        private void statusImage_DoubleClick(object sender, EventArgs e)
        {
            pauseBackupToolStripMenuItem_Click(sender, e);
        }

        private void PauseDurationMenu_Click(object sender, EventArgs e)
        {
            Program.LiveControl.Pause((string)((ToolStripItem)sender).Tag);
        }

        private void ServiceStatus_Resize(object sender, EventArgs e)
        {
            ProgressMessage.MaximumSize = new Size(WorkProgressbar.Width, ProgressMessage.MaximumSize.Height);
        }

        private void ServiceStatus_Activated(object sender, EventArgs e)
        {
            Program.DisplayHelper.ResetCurrentIcon();
        }

        private void wizardLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Program.DisplayHelper.ShowWizard();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Program.DisplayHelper.ShowSettings();
        }

        private void QuickActions_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBoxItemPair<QuickActionType> c = QuickActions.SelectedItem as ComboBoxItemPair<QuickActionType>;
            if (c != null)
            {
                switch (c.Value)
                {
                    case QuickActionType.Pause:
                        Program.LiveControl.Pause();
                        break;
                    case QuickActionType.Resume:
                        Program.LiveControl.Resume();
                        break;
                    case QuickActionType.Pause5Min:
                        Program.LiveControl.Pause("5m");
                        break;
                    case QuickActionType.Pause10Min:
                        Program.LiveControl.Pause("10m");
                        break;
                    case QuickActionType.Pause15Min:
                        Program.LiveControl.Pause("15m");
                        break;
                    case QuickActionType.Pause30Min:
                        Program.LiveControl.Pause("30m");
                        break;
                    case QuickActionType.Pause60Min:
                        Program.LiveControl.Pause("60m");
                        break;
                    case QuickActionType.StopBackup:
                        Program.Runner.Stop(CloseReason.UserClosing);
                        break;
                    case QuickActionType.ThrottleDialog:
                        new ThrottleControl().ShowDialog(Program.DisplayHelper);
                        break;
                    case QuickActionType.QuitDuplicati:
                        Program.DisplayHelper.Quit();
                        break;
                }
            }

            QuickActions.SelectedIndex = 0;
        }

        private void runBackupNowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (recentBackups.SelectedItems.Count != 1)
                return;

            Log l = recentBackups.SelectedItems[0].Tag as Log;
            if (l == null || l.OwnerTask == null || l.OwnerTask.Schedule == null)
                return;

            Program.WorkThread.AddTask(new IncrementalBackupTask(l.OwnerTask.Schedule));
        }

        private void runBackupNowToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (pendingView.SelectedItems.Count != 1)
                return;

            Schedule s = pendingView.SelectedItems[0].Tag as Schedule;
            if (s == null)
                return;

            Program.WorkThread.AddTask(new IncrementalBackupTask(s));

        }

        private void ServiceStatus_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Program.TraylessMode && !Program.DisplayHelper.IsInQuit)
            {
                if (!Program.DisplayHelper.Quit())
                    e.Cancel = true;
            }
        }
     }
}