]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/console/console.cpp
Check for job_canceled() in fd_plugin code
[bacula/bacula] / bacula / src / qt-console / console / console.cpp
index facaba9e4c82330547209ca0dca6e11ea73b5133..a3b6ee6115167236ed8bbdb8825770b1cabd7725 100644 (file)
@@ -96,7 +96,7 @@ void Console::poll_messages()
       return;
    DirComm *dircomm = m_dircommHash.value(conn);
 
-   if (mainWin->m_checkMessages && dircomm->m_at_main_prompt && hasFocus()){
+   if (mainWin->m_checkMessages && dircomm->m_at_main_prompt && hasFocus() && !mainWin->getWaitState()){
       messagesPending(true);
       dircomm->write(".messages");
       displayToPrompt(conn);
@@ -121,10 +121,9 @@ void Console::connect_dir()
 
    if (dircomm->connect_dir()) {
       if (mainWin->m_connDebug)
-         Pmsg0(000, "DirComm 0 Seems to have Connected\n");
+         Pmsg1(000, "DirComm 0 Seems to have Connected %s\n", m_dir->name());
       beginNewCommand(0);
    }
-   populateLists(true);
    mainWin->set_status(_("Connected"));
    
    startTimer();                      /* start message timer */
@@ -137,17 +136,18 @@ void Console::connect_dir()
 void Console::populateLists(bool forcenew)
 {
    int conn;
-   if (forcenew)
+   if (forcenew) {
       if (!newDirComm(conn)) {
-         Pmsg0(000, "newDirComm Seems to Failed to create a connection for populateLists\n");
+         Pmsg1(000, "newDirComm Seems to Failed to create a connection for populateLists %s\n", m_dir->name());
          return;
       }
-   else
+   } else {
       if(!availableDirComm(conn)) {
-         Pmsg0(000, "availableDirComm Seems to Failed to find a connection for populateLists\n");
+         Pmsg1(000, "availableDirComm Seems to Failed to find a connection for populateListsi %s\n", m_dir->name());
          return;
       }
-  populateLists(conn);
+   }
+   populateLists(conn);
 }
 
 void Console::populateLists(int conn)
@@ -171,10 +171,11 @@ void Console::populateLists(int conn)
    dir_cmd(conn, ".levels", level_list);
 
    if (mainWin->m_connDebug) {
-      QString dbgmsg = QString("jobs=%1 clients=%2 filesets=%3 msgs=%4 pools=%5 storage=%6 types=%7 levels=%8\n")
+      QString dbgmsg = QString("jobs=%1 clients=%2 filesets=%3 msgs=%4 pools=%5 storage=%6 types=%7 levels=%8 conn=%9 %10\n")
         .arg(job_list.count()).arg(client_list.count()).arg(fileset_list.count()).arg(messages_list.count())
-        .arg(pool_list.count()).arg(storage_list.count()).arg(type_list.count()).arg(level_list.count());
-      Pmsg1(000, "%s\n", dbgmsg.toUtf8().data());
+        .arg(pool_list.count()).arg(storage_list.count()).arg(type_list.count()).arg(level_list.count())
+        .arg(conn).arg(m_dir->name());
+      Pmsg1(000, "%s", dbgmsg.toUtf8().data());
    }
 }
 
@@ -193,11 +194,11 @@ bool Console::dir_cmd(QString &cmd, QStringList &results)
 bool Console::dir_cmd(const char *cmd, QStringList &results)
 {
    int conn;
-   if(availableDirComm(conn)) {
+   if (availableDirComm(conn)) {
       dir_cmd(conn, cmd, results);
       return true;
    } else {
-      Pmsg0(000, "dir_cmd Seems to Failed to find a connection\n");
+      Pmsg1(000, "dir_cmd Seems to Failed to find a connection %s\n", m_dir->name());
       return false;
    }
 }
@@ -212,8 +213,10 @@ bool Console::dir_cmd(int conn, const char *cmd, QStringList &results)
    DirComm *dircomm = m_dircommHash.value(conn);
    int stat;
 
-   if (mainWin->m_connDebug)
-      Pmsg2(000, "dir_cmd conn %i %s\n", conn, cmd);
+   if (mainWin->m_connDebug) {
+      QString dbgmsg = QString("dir_cmd conn %1 %2 %3\n").arg(conn).arg(m_dir->name()).arg(cmd);
+      Pmsg1(000, "%s", dbgmsg.toUtf8().data());
+   }
    notify(conn, false);
    dircomm->write(cmd);
    while ((stat = dircomm->read()) > 0 && dircomm->is_in_command()) {
@@ -299,25 +302,45 @@ bool Console::sql_cmd(int &conn, const char *query, QStringList &results, bool d
    return true;              /* ***FIXME*** return any command error */
 }
 
-/* Send a command to the Director */
+/* 
+ * Overloads for
+ * Sending a command to the Director
+ */
 int Console::write_dir(const char *msg)
 {
    int conn;
-   if(availableDirComm(conn))
+   if (availableDirComm(conn))
       write_dir(conn, msg);
    return conn;
 }
 
-/* Send a command to the Director */
+int Console::write_dir(const char *msg, bool dowait)
+{
+   int conn;
+   if (availableDirComm(conn))
+      write_dir(conn, msg, dowait);
+   return conn;
+}
+
 void Console::write_dir(int conn, const char *msg)
+{
+   write_dir(conn, msg, true);
+}
+
+/*
+ * Send a command to the Director
+ */
+void Console::write_dir(int conn, const char *msg, bool dowait)
 {
    DirComm *dircomm = m_dircommHash.value(conn);
 
    if (dircomm->m_sock) {
       mainWin->set_status(_("Processing command ..."));
-      mainWin->waitEnter();
+      if (dowait)
+         mainWin->waitEnter();
       dircomm->write(msg);
-      mainWin->waitExit();
+      if (dowait)
+         mainWin->waitExit();
    } else {
       mainWin->set_status( tr(" Director not connected. Click on connect button."));
       mainWin->actionConnect->setIcon(QIcon(":images/disconnected.png"));
@@ -357,8 +380,11 @@ bool Console::get_job_defaults(int &conn, struct job_defaults &job_defs, bool do
       conn = notifyOff();
    beginNewCommand(conn);
    DirComm *dircomm = m_dircommHash.value(conn);
+   bool prevWaitState = mainWin->getWaitState();
+   if (!prevWaitState)
+      mainWin->waitEnter();
    if (mainWin->m_connDebug)
-      Pmsg1(000, "job_defaults conn %i\n", conn);
+      Pmsg2(000, "job_defaults conn %i %s\n", conn, m_dir->name());
    scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);
    dircomm->write(scmd);
    while ((stat = dircomm->read()) > 0) {
@@ -421,11 +447,15 @@ bool Console::get_job_defaults(int &conn, struct job_defaults &job_defs, bool do
 
    if (donotify)
       notify(conn, true);
+   if (!prevWaitState)
+      mainWin->waitExit();
    return true;
 
 bail_out:
    if (donotify)
       notify(conn, true);
+   if (!prevWaitState)
+      mainWin->waitExit();
    return false;
 }
 
@@ -537,7 +567,6 @@ void Console::display_html(const QString buf)
 /* Position cursor to end of screen */
 void Console::update_cursor()
 {
-   QApplication::restoreOverrideCursor();
    m_textEdit->moveCursor(QTextCursor::End);
    m_textEdit->ensureCursorVisible();
 }
@@ -549,6 +578,7 @@ void Console::beginNewCommand(int conn)
    for (int i=0; i < 3; i++) {
       dircomm->write(".");
       while (dircomm->read() > 0) {
+         Pmsg2(000, "begin new command loop %i %s\n", i, m_dir->name());
          if (mainWin->m_displayAll) display_text(dircomm->msg());
       }
       if (dircomm->m_at_main_prompt) {
@@ -564,7 +594,7 @@ void Console::displayToPrompt(int conn)
 
    int stat = 0;
    QString buf;
-   if (mainWin->m_commDebug) Pmsg0(000, "DisplaytoPrompt\n");
+   if (mainWin->m_commDebug) Pmsg1(000, "DisplaytoPrompt %s\n", m_dir->name());
    while (!dircomm->m_at_prompt) {
       if ((stat=dircomm->read()) > 0) {
          buf += dircomm->msg();
@@ -576,7 +606,7 @@ void Console::displayToPrompt(int conn)
       }
    }
    display_text(buf);
-   if (mainWin->m_commDebug) Pmsg1(000, "endDisplaytoPrompt=%d\n", stat);
+   if (mainWin->m_commDebug) Pmsg2(000, "endDisplaytoPrompt=%d %s\n", stat, m_dir->name());
 }
 
 void Console::discardToPrompt(int conn)
@@ -584,15 +614,18 @@ void Console::discardToPrompt(int conn)
    DirComm *dircomm = m_dircommHash.value(conn);
 
    int stat = 0;
-   if (mainWin->m_commDebug) Pmsg0(000, "discardToPrompt\n");
+   if (mainWin->m_commDebug) Pmsg1(000, "discardToPrompt %s\n", m_dir->name());
    if (mainWin->m_displayAll) {
       displayToPrompt(conn);
    } else {
       while (!dircomm->m_at_prompt) {
-         stat=dircomm->read();
+         stat = dircomm->read();
+         if (stat < 0) {
+            break;
+         }
       }
    }
-   if (mainWin->m_commDebug) Pmsg1(000, "endDiscardToPrompt=%d\n", stat);
+   if (mainWin->m_commDebug) Pmsg2(000, "endDiscardToPrompt=%d %s\n", stat, m_dir->name());
 }
 
 /*
@@ -610,7 +643,7 @@ void Console::discardToPrompt(int conn)
 int Console::notifyOff()
 { 
    int conn = 0;
-   if(availableDirComm(conn))
+   if (availableDirComm(conn))
       notify(conn, false);
    return conn;
 }
@@ -778,14 +811,15 @@ bool Console::newDirComm(int &conn)
    m_dircommCounter += 1;
    conn = m_dircommCounter;
    if (mainWin->m_connDebug)
-      Pmsg1(000, "DirComm %i About to Create and Connect\n", m_dircommCounter);
+      Pmsg2(000, "DirComm %i About to Create and Connect %s\n", m_dircommCounter, m_dir->name());
    DirComm *dircomm = new DirComm(this, m_dircommCounter);
    m_dircommHash.insert(m_dircommCounter, dircomm);
    bool success = dircomm->connect_dir();
-   if (mainWin->m_connDebug)
+   if (mainWin->m_connDebug) {
       if (success)
-         Pmsg1(000, "DirComm %i Connected\n", conn);
+         Pmsg2(000, "DirComm %i Connected %s\n", conn, m_dir->name());
       else
-         Pmsg1(000, "DirComm %i NOT Connected\n", conn);
+         Pmsg2(000, "DirComm %i NOT Connected %s\n", conn, m_dir->name());
+   }
    return success;
 }