MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
{
+ app->setOverrideCursor(QCursor(Qt::WaitCursor));
m_isClosing = false;
+ m_waitState = false;
+ m_doConnect = false;
+ m_treeStackTrap = false;
m_dtformat = "yyyy-MM-dd HH:mm:ss";
mainWin = this;
setupUi(this); /* Setup UI defined by main.ui (designer) */
treeWidget->setColumnCount(1);
treeWidget->setHeaderLabel( tr("Select Page") );
treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
-
+ // tabWidget->setTabsClosable(true); /* wait for QT 4.5 */
createPages();
- resetFocus();
-
- createConnections();
+ resetFocus(); /* lineEdit->setFocus() */
#ifndef HAVE_QWT
actionJobPlot->setEnabled(false);
readSettings();
- foreach(Console *console, m_consoleHash) {
+ foreach(Console *console, m_consoleHash)
console->connect_dir();
- }
m_currentConsole = (Console*)getFromHash(m_firstItem);
- m_currentConsole->setCurrent();
+ QTimer::singleShot(750, this, SLOT(popLists()));
if (m_miscDebug) {
QString directoryResourceName;
m_currentConsole->getDirResName(directoryResourceName);
}
}
+void MainWin::popLists()
+{
+ foreach(Console *console, m_consoleHash)
+ console->populateLists(true);
+ app->restoreOverrideCursor();
+ m_doConnect = true;
+ connectConsoleSignals();
+ connectSignals();
+ m_currentConsole->setCurrent();
+}
+
void MainWin::createPages()
{
DIRRES *dir;
foreach_res(dir, R_DIRECTOR) {
/* Create console tree stacked widget item */
- m_currentConsole = new Console(stackedWidget);
+ m_currentConsole = new Console(tabWidget);
m_currentConsole->setDirRes(dir);
m_currentConsole->readSettings();
new DirStat();
treeWidget->expandItem(topItem);
- stackedWidget->setCurrentWidget(m_currentConsole);
+ tabWidget->setCurrentWidget(m_currentConsole);
}
UnlockRes();
}
lineEdit->setText(m_cmd_history[m_cmd_last]);
}
-void MainWin::createConnections()
+void MainWin::connectSignals()
{
/* Connect signals to slots */
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
connect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
- connect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
- connect(stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
+ connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+ connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelButtonClicked()));
connect(actionRun, SIGNAL(triggered()), this, SLOT(runButtonClicked()));
connect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow()));
connect(actionClosePage, SIGNAL(triggered()), this, SLOT(closePage()));
connect(actionPreferences, SIGNAL(triggered()), this, SLOT(setPreferences()));
+ connect(actionRepopLists, SIGNAL(triggered()), this, SLOT(repopLists()));
+ connect(actionReloadRepop, SIGNAL(triggered()), this, SLOT(reloadRepopLists()));
}
-void MainWin::disconnectConnections()
+void MainWin::disconnectSignals()
{
/* Connect signals to slots */
disconnect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
disconnect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
disconnect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
disconnect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
- disconnect(stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
+ disconnect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
disconnect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
disconnect(actionLabel, SIGNAL(triggered()), this, SLOT(labelButtonClicked()));
disconnect(actionRun, SIGNAL(triggered()), this, SLOT(runButtonClicked()));
disconnect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow()));
disconnect(actionClosePage, SIGNAL(triggered()), this, SLOT(closePage()));
disconnect(actionPreferences, SIGNAL(triggered()), this, SLOT(setPreferences()));
+ disconnect(actionRepopLists, SIGNAL(triggered()), this, SLOT(repopLists()));
+ disconnect(actionReloadRepop, SIGNAL(triggered()), this, SLOT(reloadRepopLists()));
}
/*
*/
void MainWin::waitEnter()
{
+ if (m_waitState){
+ if (mainWin->m_connDebug)
+ Pmsg0(000, "Should Never Get Here DANGER DANGER, for now I'll return\n");
+ return;
+ }
+ m_waitState = true;
+ if (mainWin->m_connDebug)
+ Pmsg0(000, "Entering Wait State\n");
app->setOverrideCursor(QCursor(Qt::WaitCursor));
- disconnectConnections();
+ disconnectSignals();
+ disconnectConsoleSignals(m_currentConsole);
+ m_waitTreeItem = treeWidget->currentItem();
}
/*
*/
void MainWin::waitExit()
{
+ m_waitState = false;
+ if (mainWin->m_connDebug) Pmsg0(000, "Exiting Wait State\n");
app->restoreOverrideCursor();
- createConnections();
+ if (m_waitTreeItem != treeWidget->currentItem())
+ treeWidget->setCurrentItem(m_waitTreeItem);
+ if (m_doConnect) {
+ connectSignals();
+ connectConsoleSignals();
+ }
+}
+
+void MainWin::connectConsoleSignals()
+{
+ connect(actionConnect, SIGNAL(triggered()), m_currentConsole, SLOT(connect_dir()));
+ connect(actionSelectFont, SIGNAL(triggered()), m_currentConsole, SLOT(set_font()));
+ connect(actionMessages, SIGNAL(triggered()), m_currentConsole, SLOT(messages()));
+}
+
+void MainWin::disconnectConsoleSignals(Console *console)
+{
+ disconnect(actionConnect, SIGNAL(triggered()), console, SLOT(connect_dir()));
+ disconnect(actionMessages, SIGNAL(triggered()), console, SLOT(messages()));
+ disconnect(actionSelectFont, SIGNAL(triggered()), console, SLOT(set_font()));
+}
+
+
+/*
+ * Two functions to respond to menu items to repop lists and execute reload and repopulate
+ * the lists for jobs, clients, filesets .. ..
+ */
+void MainWin::repopLists()
+{
+ m_currentConsole->populateLists(false);
+}
+void MainWin::reloadRepopLists()
+{
+ QString cmd = "reload";
+ m_currentConsole->consoleCommand(cmd);
+ m_currentConsole->populateLists(false);
}
/*
{
m_isClosing = true;
writeSettings();
+ /* Remove all groups from settings for OpenOnExit so that we can start some of the status windows */
+ foreach(Console *console, m_consoleHash){
+ QSettings settings(console->m_dir->name(), "bat");
+ settings.beginGroup("OpenOnExit");
+ settings.remove("");
+ settings.endGroup();
+ }
/* close all non console pages, this will call settings in destructors */
while (m_consoleHash.count() < m_pagehash.count()) {
foreach(Pages *page, m_pagehash) {
settings.setValue("winPos", pos());
settings.setValue("state", saveState());
settings.endGroup();
+
}
void MainWin::readSettings()
/* Is this a page that has been inserted into the hash */
if (getFromHash(item)) {
Pages* page = getFromHash(item);
- int stackindex=stackedWidget->indexOf(page);
+ int stackindex=tabWidget->indexOf(page);
if (stackindex >= 0) {
- stackedWidget->setCurrentWidget(page);
+ tabWidget->setCurrentWidget(page);
}
/* run the virtual function in case this class overrides it */
page->PgSeltreeWidgetClicked();
/* this condition prevents a segfault. The first time there is no previousitem*/
if (previousitem) {
+ if (m_treeStackTrap == false) { /* keep track of previous items for going Back */
+ m_treeWidgetStack.append(previousitem);
+ }
/* knowing the treeWidgetItem, get the page from the hash */
previousPage = getFromHash(previousitem);
previousConsole = m_consoleHash.value(previousitem);
if ((previousPage) || (previousConsole)) {
if (nextConsole != previousConsole) {
/* remove connections to the current console */
- disconnect(actionConnect, SIGNAL(triggered()), previousConsole, SLOT(connect_dir()));
- disconnect(actionStatusDir, SIGNAL(triggered()), previousConsole, SLOT(status_dir()));
- disconnect(actionMessages, SIGNAL(triggered()), previousConsole, SLOT(messages()));
- disconnect(actionSelectFont, SIGNAL(triggered()), previousConsole, SLOT(set_font()));
+ disconnectConsoleSignals(previousConsole);
QTreeWidgetItem *dirItem = previousConsole->directorTreeItem();
QBrush greyBrush(Qt::lightGray);
dirItem->setBackground(0, greyBrush);
if (nextConsole != previousConsole) {
/* make connections to the current console */
m_currentConsole = nextConsole;
- connect(actionConnect, SIGNAL(triggered()), m_currentConsole, SLOT(connect_dir()));
- connect(actionSelectFont, SIGNAL(triggered()), m_currentConsole, SLOT(set_font()));
- connect(actionStatusDir, SIGNAL(triggered()), m_currentConsole, SLOT(status_dir()));
- connect(actionMessages, SIGNAL(triggered()), m_currentConsole, SLOT(messages()));
+ connectConsoleSignals();
setMessageIcon();
/* Set director's tree widget background to magenta for ease of identification */
QTreeWidgetItem *dirItem = m_currentConsole->directorTreeItem();
dirItem->setBackground(0, magentaBrush);
}
/* set the value for the currently active console */
- int stackindex = stackedWidget->indexOf(nextPage);
+ int stackindex = tabWidget->indexOf(nextPage);
/* Is this page currently on the stack or is it undocked */
if (stackindex >= 0) {
/* put this page on the top of the stack */
- stackedWidget->setCurrentIndex(stackindex);
+ tabWidget->setCurrentIndex(stackindex);
} else {
/* it is undocked, raise it to the front */
nextPage->raise();
*/
void MainWin::input_line()
{
+ int conn;
QString cmdStr = lineEdit->text(); /* Get the text */
lineEdit->clear(); /* clear the lineEdit box */
if (m_currentConsole->is_connected()) {
- /* Use consoleInput to allow typing anything */
- m_currentConsole->consoleInput(cmdStr);
+ if (m_currentConsole->currentDirComm(conn)) {
+ m_currentConsole->consoleCommand(cmdStr, conn);
+ } else {
+ /* Use consoleCommand to allow typing anything */
+ m_currentConsole->consoleCommand(cmdStr);
+ }
} else {
set_status(tr("Director not connected. Click on connect button."));
}
*/
void MainWin::undockWindowButton()
{
- Pages* page = (Pages*)stackedWidget->currentWidget();
+ Pages* page = (Pages*)tabWidget->currentWidget();
page->togglePageDocking();
}
void MainWin::stackItemChanged(int)
{
if (m_isClosing) return; /* if closing the application, do nothing here */
- Pages* page = (Pages*)stackedWidget->currentWidget();
+ Pages* page = (Pages*)tabWidget->currentWidget();
/* run the virtual function in case this class overrides it */
page->currentStackItem();
}
{
return m_currentConsole;
}
+
/* Quick function to return the tree item for the director */
QTreeWidgetItem *MainWin::currentTopItem()
{
prefs.daysSpinBox->setValue(m_daysLimitVal);
prefs.checkMessages->setCheckState(m_checkMessages ? Qt::Checked : Qt::Unchecked);
prefs.checkMessagesSpin->setValue(m_checkMessagesInterval);
- prefs.refreshStatusDir->setCheckState(m_refreshStatusDir ? Qt::Checked : Qt::Unchecked);
- prefs.refreshStatusDirSpin->setValue(m_refreshStatusDirInterval);
prefs.executeLongCheckBox->setCheckState(m_longList ? Qt::Checked : Qt::Unchecked);
prefs.rtPopDirCheckBox->setCheckState(m_rtPopDirDebug ? Qt::Checked : Qt::Unchecked);
prefs.rtDirCurICCheckBox->setCheckState(m_rtDirCurICDebug ? Qt::Checked : Qt::Unchecked);
mainWin->m_daysLimitVal = this->daysSpinBox->value();
mainWin->m_checkMessages = this->checkMessages->checkState() == Qt::Checked;
mainWin->m_checkMessagesInterval = this->checkMessagesSpin->value();
- mainWin->m_refreshStatusDir = this->refreshStatusDir->checkState() == Qt::Checked;
- mainWin->m_refreshStatusDirInterval = this->refreshStatusDirSpin->value();
mainWin->m_longList = this->executeLongCheckBox->checkState() == Qt::Checked;
mainWin->m_rtPopDirDebug = this->rtPopDirCheckBox->checkState() == Qt::Checked;
settings.beginGroup("Timers");
settings.setValue("checkMessages", mainWin->m_checkMessages);
settings.setValue("checkMessagesInterval", mainWin->m_checkMessagesInterval);
- settings.setValue("refreshStatusDir", mainWin->m_refreshStatusDir);
- settings.setValue("refreshStatusDirInterval", mainWin->m_refreshStatusDirInterval);
settings.endGroup();
settings.beginGroup("Misc");
settings.setValue("longList", mainWin->m_longList);
settings.beginGroup("Timers");
m_checkMessages = settings.value("checkMessages", false).toBool();
m_checkMessagesInterval = settings.value("checkMessagesInterval", 28).toInt();
- m_refreshStatusDir = settings.value("refreshStatusDir", false).toBool();
- m_refreshStatusDirInterval = settings.value("refreshStatusDirInterval", 28).toInt();
settings.endGroup();
settings.beginGroup("Misc");
m_longList = settings.value("longList", false).toBool();
else
actionMessages->setIcon(QIcon(QString::fromUtf8(":/images/mail-message-new.png")));
}
+
+void MainWin::goToPreviousPage()
+{
+ m_treeStackTrap = true;
+ bool done = false;
+ while (!done) {
+ /* If stack list is emtpty, then done */
+ if (m_treeWidgetStack.isEmpty()) {
+ done = true;
+ } else {
+ QTreeWidgetItem* testItem = m_treeWidgetStack.takeLast();
+ QTreeWidgetItemIterator it(treeWidget);
+ /* lets avoid a segfault by setting an item current that no longer exists */
+ while (*it) {
+ if (*it == testItem) {
+ if (testItem != treeWidget->currentItem()) {
+ treeWidget->setCurrentItem(testItem);
+ done = true;
+ }
+ break;
+ }
+ ++it;
+ }
+ }
+ }
+ m_treeStackTrap = false;
+}