Skip to content

Commit

Permalink
Shell|GUI: History of opened servers, separate menu item for window c…
Browse files Browse the repository at this point in the history
…lose
  • Loading branch information
skyjake committed Feb 9, 2013
1 parent fc770c9 commit cace600
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
21 changes: 20 additions & 1 deletion doomsday/tools/shell/shell-gui/src/guishellapp.cpp
Expand Up @@ -52,15 +52,20 @@ GuiShellApp::GuiShellApp(int &argc, char **argv)
setApplicationName ("doomsday-shell-gui");
setApplicationVersion (SHELL_VERSION);

#ifdef MACOSX
setQuitOnLastWindowClosed(false);
#endif

d->menuBar = new QMenuBar(0);

QMenu *menu = d->menuBar->addMenu(tr("Server"));
menu->addAction(tr("Connect..."), this, SLOT(connectToServer()),
QKeySequence(tr("Ctrl+O", "Server|Connect")));
menu->addAction(tr("Disconnect"), this, SLOT(disconnectFromServer()),
QKeySequence(tr("Ctrl+W", "Server|Disconnect")));
QKeySequence(tr("Ctrl+D", "Server|Disconnect")));
menu->addSeparator();
menu->addAction(tr("Close Window"), this, SLOT(closeActiveWindow()),
QKeySequence(tr("Ctrl+W", "Server|Close Window")));
menu->addSeparator();
menu->addAction(tr("Start Local Server"), this, SLOT(startLocalServer()),
QKeySequence(tr("Ctrl+N", "Server|Start Local Server")));
Expand All @@ -81,6 +86,7 @@ GuiShellApp::~GuiShellApp()
MainWindow *GuiShellApp::newOrReusedConnectionWindow()
{
MainWindow *found = 0;
QWidget *other = activeWindow(); // for positioning a new window

// Look for a window with a closed connection.
foreach(MainWindow *win, d->windows)
Expand All @@ -93,12 +99,19 @@ MainWindow *GuiShellApp::newOrReusedConnectionWindow()
d->windows.removeOne(win);
break;
}
if(!other) other = win;
}

if(!found)
{
found = new MainWindow;
connect(found, SIGNAL(closed(MainWindow *)), this, SLOT(windowClosed(MainWindow *)));

// Initial position and size.
if(other)
{
found->move(other->pos() + QPoint(30, 30));
}
}

d->windows.prepend(found);
Expand Down Expand Up @@ -147,6 +160,12 @@ void GuiShellApp::disconnectFromServer()
}
}

void GuiShellApp::closeActiveWindow()
{
QWidget *win = activeWindow();
if(win) win->close();
}

void GuiShellApp::startLocalServer()
{
}
Expand Down
1 change: 1 addition & 0 deletions doomsday/tools/shell/shell-gui/src/guishellapp.h
Expand Up @@ -42,6 +42,7 @@ public slots:
void connectToServer();
void connectToLocalServer();
void disconnectFromServer();
void closeActiveWindow();
void startLocalServer();
void updateLocalServerMenu();
void aboutShell();
Expand Down
37 changes: 34 additions & 3 deletions doomsday/tools/shell/shell-gui/src/opendialog.cpp
Expand Up @@ -33,14 +33,17 @@
using namespace de;
using namespace de::shell;

static int const MAX_HISTORY_SIZE = 10;

DENG2_PIMPL(OpenDialog)
{
QComboBox *address;
QLabel *localCount;
int firstFoundIdx;
QStringList history;
bool edited;

Instance(Public &i) : Private(i)
Instance(Public &i) : Private(i), edited(false)
{
// Restore the historical entries.
QSettings st;
Expand Down Expand Up @@ -102,9 +105,10 @@ DENG2_PIMPL(OpenDialog)
OpenDialog::OpenDialog(QWidget *parent)
: QDialog(parent), d(new Instance(*this))
{
connect(this, SIGNAL(accepted()), this, SLOT(saveState()));

updateLocalList(true /* autoselect first found server */);

connect(d->address, SIGNAL(editTextChanged(QString)), this, SLOT(textEdited(QString)));
connect(this, SIGNAL(accepted()), this, SLOT(saveState()));
}

OpenDialog::~OpenDialog()
Expand Down Expand Up @@ -190,6 +194,33 @@ void OpenDialog::updateLocalList(bool autoselect)

void OpenDialog::saveState()
{
if(d->edited)
{
String text = d->address->itemText(0);
d->history.removeAll(text);
d->history.prepend(text);

// Make sure there aren't too many entries.
while(d->history.size() > MAX_HISTORY_SIZE)
{
d->history.removeLast();
}
}

QSettings st;
st.setValue("OpenDialog.history", d->history);
}

void OpenDialog::textEdited(QString text)
{
if(!d->edited)
{
d->edited = true;
d->address->insertItem(0, text);
d->address->setCurrentIndex(0);
}
else
{
d->address->setItemText(0, text);
}
}
1 change: 1 addition & 0 deletions doomsday/tools/shell/shell-gui/src/opendialog.h
Expand Up @@ -22,6 +22,7 @@ public slots:

protected slots:
void saveState();
void textEdited(QString);

private:
struct Instance;
Expand Down
3 changes: 1 addition & 2 deletions doomsday/tools/shell/shell-gui/src/qtguiapp.cpp
Expand Up @@ -46,8 +46,7 @@ struct QtGuiApp::Instance

QtGuiApp::QtGuiApp(int &argc, char **argv)
: QApplication(argc, argv), d(new Instance)
{
}
{}

QtGuiApp::~QtGuiApp()
{
Expand Down

0 comments on commit cace600

Please sign in to comment.