summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Cremer <HolgerCremer@gmail.com>2015-06-11 21:23:38 +0200
committerHolger Cremer <HolgerCremer@gmail.com>2015-06-12 19:31:23 +0200
commitdf4d78a79f480c93880f11ec72516d3ac76290c1 (patch)
tree0f91af4f63d458008e84cab0b65cc4155a4d9f81
parent9d61f22844bdfcbe983976aaf5176d08e741a6de (diff)
downloadserial-barcode-scanner-df4d78a79f480c93880f11ec72516d3ac76290c1.tar.bz2
show the countdown value in the dialog title
-rw-r--r--src/curses-ui/curses-ui.vala2
-rw-r--r--src/curses-ui/dialog.vala37
2 files changed, 34 insertions, 5 deletions
diff --git a/src/curses-ui/curses-ui.vala b/src/curses-ui/curses-ui.vala
index e866c6e..b3efdd5 100644
--- a/src/curses-ui/curses-ui.vala
+++ b/src/curses-ui/curses-ui.vala
@@ -81,7 +81,7 @@ public class CursesUI {
}
public void dialog_open(string title, string message, int closeAfter=0) {
- dialog = new Dialog(message, title);
+ dialog = new Dialog(message, title, closeAfter);
if (closeAfter > 0) {
Timeout.add_seconds(closeAfter, close);
}
diff --git a/src/curses-ui/dialog.vala b/src/curses-ui/dialog.vala
index a8585d4..7d2902b 100644
--- a/src/curses-ui/dialog.vala
+++ b/src/curses-ui/dialog.vala
@@ -19,14 +19,19 @@ public class Dialog {
Window win;
Window subwin;
- public Dialog(string message, string title = "KtT Shopsystem Error", int h=16, int w=60)
+ string dialogTitle;
+ int dialogWidth;
+ int countdownValue;
+
+ public Dialog(string message, string title = "KtT Shopsystem Error", int titleCountdown=0, int h=16, int w=60)
requires (title.length <= w-4)
{
+ dialogTitle = title;
+ dialogWidth = w;
+ countdownValue = titleCountdown;
int y = LINES/2-h/2;
int x = COLS/2-w/2;
- int title_x = (w-title.length)/2;
-
win = new Window(h, w, y, x);
/* make the dialog white on red */
@@ -41,11 +46,35 @@ public class Dialog {
/* dialog title */
win.box(0,0);
+ setTitle();
+ win.refresh();
+
+ if (countdownValue > 0) {
+ Timeout.add_seconds(1, decrementTitleCountdown);
+ }
+ }
+
+ private void setTitle() {
+ var title = dialogTitle;
+ if (countdownValue > 0) {
+ title = "%s (%d)".printf(title, countdownValue);
+ }
+ int title_x = (dialogWidth-title.length)/2;
win.mvaddstr(0, title_x, title);
- win.mvaddch(0, title_x-2, Acs.RTEE);
+ win.mvaddch(0, title_x-2, Acs.RTEE);
win.mvaddch(0, title_x-1, ' ');
win.mvaddch(0, title_x+title.length, ' ');
win.mvaddch(0, title_x+title.length+1, Acs.LTEE);
+ // fixing the countdown (for a reasonable countdown)
+ win.mvaddch(0, title_x+title.length+2, Acs.HLINE);
+ win.mvaddch(0, title_x+title.length+3, Acs.HLINE);
+ }
+
+ private bool decrementTitleCountdown() {
+ countdownValue--;
+ setTitle();
win.refresh();
+ // run again until countdown is zero
+ return countdownValue > 0;
}
}