From af228399838423e650ead4aad551a8627ffaf058 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 24 Jul 2007 18:36:08 +0000 Subject: [PATCH] Implement PopUp YES/NO dialog for bat. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5237 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/backup.c | 2 +- bacula/src/dird/getmsg.c | 48 +++++++++++------------ bacula/src/dird/ua_cmds.c | 23 +++++++++-- bacula/src/dird/ua_input.c | 1 + bacula/src/dird/ua_label.c | 2 +- bacula/src/dird/ua_update.c | 7 +++- bacula/src/lib/bsock.h | 5 ++- bacula/src/qt-console/console/console.cpp | 4 ++ bacula/src/qt-console/select/select.cpp | 28 +++++++++++++ bacula/src/qt-console/select/select.h | 10 +++++ bacula/src/version.h | 4 +- bacula/technotes-2.1 | 2 + 12 files changed, 101 insertions(+), 35 deletions(-) diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 93de742f03..a6a0b0aeed 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -293,7 +293,7 @@ int wait_for_job_termination(JCR *jcr) if (is_bnet_error(fd)) { Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"), - job_type_to_str(jcr->JobType), bnet_strerror(fd)); + job_type_to_str(jcr->JobType), fd->bstrerror()); } bnet_sig(fd, BNET_TERMINATE); /* tell Client we are terminating */ diff --git a/bacula/src/dird/getmsg.c b/bacula/src/dird/getmsg.c index 7a183ba43b..ae4a190bf6 100644 --- a/bacula/src/dird/getmsg.c +++ b/bacula/src/dird/getmsg.c @@ -1,29 +1,7 @@ -/* - * - * Bacula Director -- routines to receive network data and - * handle network signals. These routines handle the connections - * to the Storage daemon and the File daemon. - * - * Kern Sibbald, August MM - * - * This routine runs as a thread and must be thread reentrant. - * - * Basic tasks done here: - * Handle network signals (signals). - * Signals always have return status 0 from bnet_recv() and - * a zero or negative message length. - * Pass appropriate messages back to the caller (responses). - * Responses always have a digit as the first character. - * Handle requests for message and catalog services (requests). - * Requests are any message that does not begin with a digit. - * In affect, they are commands. - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -47,6 +25,28 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Bacula Director -- routines to receive network data and + * handle network signals. These routines handle the connections + * to the Storage daemon and the File daemon. + * + * Kern Sibbald, August MM + * + * This routine runs as a thread and must be thread reentrant. + * + * Basic tasks done here: + * Handle network signals (signals). + * Signals always have return status 0 from bnet_recv() and + * a zero or negative message length. + * Pass appropriate messages back to the caller (responses). + * Responses always have a digit as the first character. + * Handle requests for message and catalog services (requests). + * Requests are any message that does not begin with a digit. + * In affect, they are commands. + * + * Version $Id$ + */ #include "bacula.h" #include "dird.h" @@ -107,7 +107,7 @@ int bget_dirmsg(BSOCK *bs) for (;;) { n = bs->recv(); - Dmsg2(900, "bget_dirmsg %d: %s", n, bs->msg); + Dmsg2(100, "bget_dirmsg %d: %s", n, bs->msg); if (is_bnet_stop(bs)) { return n; /* error or terminate */ diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 4c402fece0..d312e5b540 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -478,10 +478,19 @@ static int cancel_cmd(UAContext *ua, const char *cmd) if (do_prompt(ua, _("Job"), _("Choose Job to cancel"), buf, sizeof(buf)) < 0) { return 1; } - if (njobs == 1) { - if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) { + if (ua->api && njobs == 1) { + char nbuf[1000]; + bsnprintf(nbuf, sizeof(nbuf), _("Cancel: %s\n\n%s"), buf, + _("Confirm cancel?")); + if (!get_yesno(ua, nbuf) || ua->pint32_val == 0) { return 1; } + } else { + if (njobs == 1) { + if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) { + return 1; + } + } } sscanf(buf, "JobId=%d Job=%127s", &njobs, JobName); jcr = get_jcr_by_full_name(JobName); @@ -1364,6 +1373,7 @@ static void do_job_delete(UAContext *ua, JobId_t JobId) static int delete_volume(UAContext *ua) { MEDIA_DBR mr; + char buf[1000]; if (!select_media_dbr(ua, &mr)) { return 1; @@ -1372,7 +1382,9 @@ static int delete_volume(UAContext *ua) "and all Jobs saved on that volume from the Catalog\n"), mr.VolumeName); - if (!get_yesno(ua, _("Are you sure you want to delete this Volume? (yes/no): "))) { + bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Volume \"%s\"? (yes/no): "), + mr.VolumeName); + if (!get_yesno(ua, buf)) { return 1; } if (ua->pint32_val) { @@ -1387,13 +1399,16 @@ static int delete_volume(UAContext *ua) static int delete_pool(UAContext *ua) { POOL_DBR pr; + char buf[200]; memset(&pr, 0, sizeof(pr)); if (!get_pool_dbr(ua, &pr)) { return 1; } - if (!get_yesno(ua, _("Are you sure you want to delete this Pool? (yes/no): "))) { + bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Pool \"%s\"? (yes/no): "), + pr.Name); + if (!get_yesno(ua, buf)) { return 1; } if (ua->pint32_val) { diff --git a/bacula/src/dird/ua_input.c b/bacula/src/dird/ua_input.c index 19cfe9d307..ea27cae06e 100644 --- a/bacula/src/dird/ua_input.c +++ b/bacula/src/dird/ua_input.c @@ -147,6 +147,7 @@ bool get_yesno(UAContext *ua, const char *prompt) int ret; ua->pint32_val = 0; for (;;) { + if (ua->api) ua->UA_sock->signal(BNET_YESNO); if (!get_cmd(ua, prompt)) { return false; } diff --git a/bacula/src/dird/ua_label.c b/bacula/src/dird/ua_label.c index 077675c01b..e63b4ef1ea 100644 --- a/bacula/src/dird/ua_label.c +++ b/bacula/src/dird/ua_label.c @@ -535,7 +535,7 @@ static void label_from_barcodes(UAContext *ua, int drive) } ua->send_msg("%4d %s\n", vl->Slot, vl->VolName); } - if (!get_yesno(ua, _("Do you want to continue? (yes|no): ")) || + if (!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) || (ua->pint32_val == 0)) { goto bail_out; } diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index b55e3dd97b..f5bd5ee164 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -429,6 +429,7 @@ static int update_volume(UAContext *ua) POOL *pool; POOL_DBR pr; POOLMEM *query; + char buf[1000]; char ed1[130]; bool done = false; int i; @@ -622,7 +623,9 @@ static int update_volume(UAContext *ua) case 8: /* InChanger */ ua->info_msg(_("Current InChanger flag is: %d\n"), mr.InChanger); - if (!get_yesno(ua, _("Set InChanger flag? yes/no: "))) { + bsnprintf(buf, sizeof(buf), _("Set InChanger flag for Volume \"%s\": yes/no: "), + mr.VolumeName); + if (!get_yesno(ua, buf)) { return 0; } mr.InChanger = ua->pint32_val; @@ -649,7 +652,7 @@ static int update_volume(UAContext *ua) VolFiles = ua->pint32_val; if (VolFiles != (int)(mr.VolFiles + 1)) { ua->warning_msg(_("Normally, you should only increase Volume Files by one!\n")); - if (!get_yesno(ua, _("Continue? (yes/no): ")) || ua->pint32_val == 0) { + if (!get_yesno(ua, _("Increase Volume Files? (yes/no): ")) || ua->pint32_val == 0) { break; } } diff --git a/bacula/src/lib/bsock.h b/bacula/src/lib/bsock.h index 0f963bafeb..06247da0dc 100644 --- a/bacula/src/lib/bsock.h +++ b/bacula/src/lib/bsock.h @@ -126,6 +126,8 @@ public: bool is_duped() { return m_duped; }; bool is_terminated() { return m_terminated; }; bool is_timed_out() { return m_timed_out; }; + bool is_stop() { return errors || is_terminated(); } + bool is_error() { errno = b_errno; return errors; } void set_spooling() { m_spool = true; }; void clear_spooling() { m_spool = false; }; void set_duped() { m_duped = true; }; @@ -164,7 +166,8 @@ enum { BNET_WARNING_MSG = -20, /* Warning message */ BNET_ERROR_MSG = -21, /* Error message -- command failed */ BNET_INFO_MSG = -22, /* Info message -- status line */ - BNET_RUN_CMD = -23 /* Run command follows */ + BNET_RUN_CMD = -23, /* Run command follows */ + BNET_YESNO = -24 /* Request yes no response */ }; #define BNET_SETBUF_READ 1 /* Arg for bnet_set_buffer_size */ diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index c0ea468e08..9a81e26053 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -682,6 +682,10 @@ int Console::read() if (mainWin->m_commDebug) Pmsg0(000, "START SELECT\n"); new selectDialog(this); break; + case BNET_YESNO: + if (mainWin->m_commDebug) Pmsg0(000, "YESNO\n"); + new yesnoPopUp(this); + break; case BNET_RUN_CMD: if (mainWin->m_commDebug) Pmsg0(000, "RUN CMD\n"); new runCmdPage(); diff --git a/bacula/src/qt-console/select/select.cpp b/bacula/src/qt-console/select/select.cpp index 5d483f4beb..2bef82eaaa 100644 --- a/bacula/src/qt-console/select/select.cpp +++ b/bacula/src/qt-console/select/select.cpp @@ -95,3 +95,31 @@ void selectDialog::index_change(int index) { m_index = index; } + +/* + * Handle yesno PopUp when Bacula asks a yes/no question. + */ +/* + * Read the items for the selection + */ +yesnoPopUp::yesnoPopUp(Console *console) +{ + QMessageBox msgBox; + + setAttribute(Qt::WA_DeleteOnClose); + console->read(); /* get yesno question */ + msgBox.setWindowTitle("Bat Question"); + msgBox.setText(console->msg()); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + console->displayToPrompt(); + switch (msgBox.exec()) { + case QMessageBox::Yes: + console->write_dir("yes"); + break; + case QMessageBox::No: + console->write_dir("no"); + break; + } + console->displayToPrompt(); + mainWin->resetFocus(); +} diff --git a/bacula/src/qt-console/select/select.h b/bacula/src/qt-console/select/select.h index 4e035b1823..ae546a8888 100644 --- a/bacula/src/qt-console/select/select.h +++ b/bacula/src/qt-console/select/select.h @@ -24,4 +24,14 @@ private: }; +class yesnoPopUp : public QDialog +{ + Q_OBJECT + +public: + yesnoPopUp(Console *console); + +}; + + #endif /* _SELECT_H_ */ diff --git a/bacula/src/version.h b/bacula/src/version.h index b49f9ae369..29b7fdb7e6 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.1.29" -#define BDATE "22 July 2007" -#define LSMDATE "22Jul07" +#define BDATE "24 July 2007" +#define LSMDATE "24Jul07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 76b3e5fecd..d59230be6e 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,8 @@ Technical notes on version 2.1 General: +24Jul07 +kes Implement PopUp YES/NO dialog for bat. 23Jul07 ebl Fix a compilation bug when using #define BACL_WANT_NUMERIC_IDS 22Jul07 -- 2.39.5