]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mainwin.cpp
kes Apply fix from for building wx-console on the Mac from
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
index 54627a5ae1a55425fa113d1d7ae7192dc45c8bd8..6bfcb67a19589189473d1085b3f6a026d1c770f6 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-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.
 */
 
 /*
+ *   Version $Id$
+ *
  *  Main Window control for bat (qt-console)
  *
- *   Kern Sibbald, January MMVI
+ *   Kern Sibbald, January MMVII
  *
  */ 
 
 
 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
 {
+
    mainWin = this;
    setupUi(this);                     /* Setup UI defined by main.ui (designer) */
 
-   m_console = new Console(stackedWidget);
-   stackedWidget->setCurrentIndex(0);
+   createStackedWidgets();
 
-   lineEdit->setFocus();
+   resetFocus();
 
    createConnections();
 
@@ -54,6 +56,77 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
    m_console->connect();
 }
 
+void MainWin::createStackedWidgets()
+{
+   QTreeWidgetItem *item, *topItem;
+   m_console = new Console(stackedWidget);
+   stackedWidget->addWidget(m_console);
+
+   bRestore *brestore = new bRestore(stackedWidget);
+   stackedWidget->addWidget(brestore);
+
+   /* Just take the first Director */
+   LockRes();
+   DIRRES *dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
+   m_console->setDirRes(dir);
+   UnlockRes();
+
+   /* ***FIXME*** Dummy setup of treeWidget */
+   treeWidget->clear();
+   treeWidget->setColumnCount(1);
+   treeWidget->setHeaderLabel("Selection");
+   topItem = new QTreeWidgetItem(treeWidget);
+   topItem->setText(0, dir->name());
+   topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
+   item = new QTreeWidgetItem(topItem);
+   m_console->setTreeItem(item);
+   item->setText(0, "Console");
+   item->setText(1, "0");
+   QBrush redBrush(Qt::red);
+   item->setForeground(0, redBrush);
+   item = new QTreeWidgetItem(topItem);
+   item->setText(0, "brestore");
+   item->setText(1, "1");
+   treeWidget->expandItem(topItem);
+
+   stackedWidget->setCurrentIndex(0);
+}
+
+/*
+ * Handle up and down arrow keys for the command line
+ *  history.
+ */
+void MainWin::keyPressEvent(QKeyEvent *event)
+{
+   if (m_cmd_history.size() == 0) {
+      event->ignore();
+      return;
+   }
+   switch (event->key()) {
+   case Qt::Key_Down:
+      if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
+         event->ignore();
+         return;
+      }
+      m_cmd_last++;
+      break;
+   case Qt::Key_Up:
+      if (m_cmd_last == 0) {
+         event->ignore();
+         return;
+      }
+      if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
+         m_cmd_last = m_cmd_history.size() - 1;
+      } else {
+         m_cmd_last--;
+      }
+      break;
+   default:
+      event->ignore();
+      return;
+   }
+   lineEdit->setText(m_cmd_history[m_cmd_last]);
+}
 
 void MainWin::createConnections()
 {
@@ -76,6 +149,7 @@ void MainWin::createConnections()
    connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
    connect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelDialogClicked()));
    connect(actionRun, SIGNAL(triggered()), this,  SLOT(runDialogClicked()));
+   connect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreDialogClicked()));
 }
 
 /* 
@@ -83,9 +157,9 @@ void MainWin::createConnections()
  */
 void MainWin::closeEvent(QCloseEvent *event)
 {
-   /* ***FIXME*** close any open sockets */
    writeSettings();
    m_console->writeSettings();
+   m_console->terminate();
    event->accept();
 }
 
@@ -113,7 +187,7 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
 {
    (void)column;
    int index = item->text(1).toInt();
-   if (index >= 0 && index < 2) {
+   if (index >= 0 && index < 4) {
       stackedWidget->setCurrentIndex(index);
    }
 }
@@ -125,7 +199,7 @@ void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
    (void)column;
    int index = item->text(1).toInt();
    /* ***FIXME**** make this automatic */
-   if (index >= 0 && index < 2) {
+   if (index >= 0 && index < 4) {
       stackedWidget->setCurrentIndex(index);
    }
 }
@@ -140,6 +214,12 @@ void MainWin::runDialogClicked()
    new runDialog(m_console);
 }
 
+void MainWin::restoreDialogClicked() 
+{
+   new prerestoreDialog(m_console);
+}
+
+
 
 /*
  * The user just finished typing a line in the command line edit box
@@ -149,11 +229,13 @@ void MainWin::input_line()
    QString cmdStr = lineEdit->text();    /* Get the text */
    lineEdit->clear();                    /* clear the lineEdit box */
    if (m_console->is_connected()) {
-      m_console->set_text(cmdStr + "\n");
+      m_console->display_text(cmdStr + "\n");
       m_console->write_dir(cmdStr.toUtf8().data());         /* send to dir */
    } else {
       set_status("Director not connected. Click on connect button.");
    }
+   m_cmd_history.append(cmdStr);
+   m_cmd_last = -1;
 }
 
 
@@ -175,17 +257,14 @@ void MainWin::set_statusf(const char *fmt, ...)
    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
    va_end(arg_ptr);
    set_status(buf);
-// set_scroll_bar_to_end();
 }
 
 void MainWin::set_status_ready()
 {
-   set_status("Ready");
-// set_scroll_bar_to_end();
+   set_status(" Ready");
 }
 
 void MainWin::set_status(const char *buf)
 {
    statusBar()->showMessage(buf);
-// ready = false;
 }