Created V0.3.x branch and moved the head into the trunk directory.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@246 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2007-11-15 03:18:48 +00:00
commit 935745a08e
1318 changed files with 348809 additions and 0 deletions

View file

@ -0,0 +1,145 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, crypton
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QPoint>
#include <QSize>
#include <QPalette>
#include <QShortcut>
#include <QByteArray>
#include <QKeySequence>
#include <QDesktopWidget>
#include "rwindow.h"
/** Default constructor. */
RWindow::RWindow(QString name, QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
_name = name;
_settings = new RshareSettings();
_previouslyShown = false;
}
/** Destructor. */
RWindow::~RWindow()
{
saveWindowState();
delete _settings;
}
/** Associates a shortcut key sequence with a slot. */
void
RWindow::setShortcut(QString shortcut, const char *slot)
{
QShortcut *s = new QShortcut(QKeySequence(shortcut), this, slot, 0);
Q_UNUSED(s);
}
/** Saves the size and location of the window. */
void
RWindow::saveWindowState()
{
#if QT_VERSION >= 0x040200
saveSetting("Geometry", saveGeometry());
#else
saveSetting("Size", size());
saveSetting("Position", pos());
#endif
}
/** Restores the last size and location of the window. */
void
RWindow::restoreWindowState()
{
#if QT_VERSION >= 0x040200
QByteArray geometry = getSetting("Geometry", QByteArray()).toByteArray();
restoreGeometry(geometry);
#else
QRect screen = QDesktopWidget().availableGeometry();
/* Restore the window size. */
QSize size = getSetting("Size", QSize()).toSize();
if (!size.isEmpty()) {
size = size.boundedTo(screen.size());
resize(size);
}
/* Restore the window position. */
QPoint pos = getSetting("Position", QPoint()).toPoint();
if (!pos.isNull() && screen.contains(pos)) {
move(pos);
}
#endif
}
/** Gets the saved value of a property associated with this window object.
* If no value was saved, the default value is returned. */
QVariant
RWindow::getSetting(QString setting, QVariant defaultValue)
{
QString key = _name + "/" + setting;
return _settings->value(key, defaultValue);
}
/** Saves a value associated with a property name for this window object. */
void
RWindow::saveSetting(QString prop, QVariant value)
{
QString key = _name + "/" + prop;
_settings->setValue(key, value);
}
/** Overloaded QWidget::setVisible(). If this window is already visible and
* <b>visible</b> is true, this window will be brought to the top and given
* focus. If <b>visible</b> is false, then the window state will be saved and
* this window will be hidden. */
void
RWindow::setVisible(bool visible)
{
if (visible) {
/* If this is the first time this window is shown, restore its window
* position and size. */
if (!_previouslyShown) {
#if !defined (Q_WS_WIN)
/* Use the standard palette on non-Windows, overriding whatever was
* specified in the .ui file for this dialog. */
setPalette(QPalette());
#endif
restoreWindowState();
_previouslyShown = true;
}
/* Bring the window to the top, if it's already open. Otherwise, make the
* window visible. */
if (isVisible()) {
activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
raise();
}
} else {
/* Save the last size and position of this window. */
saveWindowState();
}
QMainWindow::setVisible(visible);
}

View file

@ -0,0 +1,70 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2007, crypton
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _RETROSHAREWINDOW_H
#define _RETROSHAREWINDOW_H
#include <QString>
#include <QWidget>
#include <QVariant>
#include <QMainWindow>
#include <config/rsharesettings.h>
class RWindow : public QMainWindow
{
Q_OBJECT
public:
/** Default constructor. */
RWindow(QString name, QWidget *parent = 0, Qt::WFlags flags = 0);
/** Destructor. */
~RWindow();
/** Associates a shortcut key sequence with a slot. */
void setShortcut(QString shortcut, const char *slot);
/** Saves the size and location of the window. */
void saveWindowState();
/** Restores the last size and location of the window. */
void restoreWindowState();
/** Gets the saved value of a property associated with this window object.
* If no value was saved, the default value is returned. */
QVariant getSetting(QString name, QVariant defaultValue);
/** Saves a value associated with a setting name for this window object. */
void saveSetting(QString name, QVariant value);
public slots:
/** Shows or hides this window. */
virtual void setVisible(bool visible);
/** Show this window. This method really just exists for subclasses to
* override, since QMainWindow::show() is non-virtual. */
virtual void showWindow() { QMainWindow::show(); }
private:
QString _name; /**< Name associated with this window. */
RshareSettings* _settings; /**< Object used to store window properties */
bool _previouslyShown; /**< True if show() has been called for this window. */
};
#endif

View file

@ -0,0 +1,166 @@
/****************************************************************
* Vidalia is distributed under the following license:
*
* Copyright (C) 2006, Matt Edman, Justin Hipple
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
/**
* \file vmessagebox.cpp
* \version $Id: vmessagebox.cpp 990 2006-06-08 03:31:27Z edmanm $
*/
#include "vmessagebox.h"
/** Default constructor. */
VMessageBox::VMessageBox(QWidget *parent)
: QMessageBox(parent)
{
}
/** Returns the button (0, 1, or 2) that is OR-ed with QMessageBox::Default,
* or 0 if none are. */
int
VMessageBox::defaultButton(int button0, int button1, int button2)
{
Q_UNUSED(button0);
int defaultButton = 0;
if (button1 & QMessageBox::Default) {
defaultButton = 1;
} else if (button2 & QMessageBox::Default) {
defaultButton = 2;
}
return defaultButton;
}
/** Returns the button (0, 1, or 2) that is OR-ed with QMessageBox::Escape,
* or -1 if none are. */
int
VMessageBox::escapeButton(int button0, int button1, int button2)
{
int escapeButton = -1;
if (button0 & QMessageBox::Escape) {
escapeButton = 0;
} else if (button1 & QMessageBox::Escape) {
escapeButton = 1;
} else if (button2 & QMessageBox::Escape) {
escapeButton = 2;
}
return escapeButton;
}
/** Returns the Button enum value from the given return value. */
int
VMessageBox::selected(int ret, int button0, int button1, int button2)
{
if (ret == 0) {
return button0;
} else if (ret == 1) {
return button1;
}
return button2;
}
/** Converts a Button enum value to a translated string. */
QString
VMessageBox::buttonText(int btn)
{
QString text;
int button = (btn & ~QMessageBox::FlagMask);
switch (button) {
case Ok: text = tr("OK"); break;
case Cancel: text = tr("Cancel"); break;
case Yes: text = tr("Yes"); break;
case No: text = tr("No"); break;
case Help: text = tr("Help"); break;
case Retry: text = tr("Retry"); break;
case ShowLog: text = tr("Show Log"); break;
case ShowSettings: text = tr("Show Settings"); break;
default: break;
}
return text;
}
/** Displays a critical message box with the given caption, message text, and
* visible buttons. To specify a button as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
int
VMessageBox::critical(QWidget *parent, QString caption, QString text,
int button0, int button1, int button2)
{
int ret = QMessageBox::critical(parent, caption, text,
VMessageBox::buttonText(button0),
VMessageBox::buttonText(button1),
VMessageBox::buttonText(button2),
VMessageBox::defaultButton(button0, button1, button2),
VMessageBox::escapeButton(button0, button1, button2));
return VMessageBox::selected(ret, button0, button1, button2);
}
/** Displays an question message box with the given caption, message text, and
* visible buttons. To specify a button as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
int
VMessageBox::question(QWidget *parent, QString caption, QString text,
int button0, int button1, int button2)
{
int ret = QMessageBox::question(parent, caption, text,
VMessageBox::buttonText(button0),
VMessageBox::buttonText(button1),
VMessageBox::buttonText(button2),
VMessageBox::defaultButton(button0, button1, button2),
VMessageBox::escapeButton(button0, button1, button2));
return VMessageBox::selected(ret, button0, button1, button2);
}
/** Displays an information message box with the given caption, message text, and
* visible buttons. To specify a button as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
int
VMessageBox::information(QWidget *parent, QString caption, QString text,
int button0, int button1, int button2)
{
int ret = QMessageBox::information(parent, caption, text,
VMessageBox::buttonText(button0),
VMessageBox::buttonText(button1),
VMessageBox::buttonText(button2),
VMessageBox::defaultButton(button0, button1, button2),
VMessageBox::escapeButton(button0, button1, button2));
return VMessageBox::selected(ret, button0, button1, button2);
}
/** Displays a warning message box with the given caption, message text, and
* visible buttons. To specify a button as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
int
VMessageBox::warning(QWidget *parent, QString caption, QString text,
int button0, int button1, int button2)
{
int ret = QMessageBox::warning(parent, caption, text,
VMessageBox::buttonText(button0),
VMessageBox::buttonText(button1),
VMessageBox::buttonText(button2),
VMessageBox::defaultButton(button0, button1, button2),
VMessageBox::escapeButton(button0, button1, button2));
return VMessageBox::selected(ret, button0, button1, button2);
}

View file

@ -0,0 +1,101 @@
/****************************************************************
* Vidalia is distributed under the following license:
*
* Copyright (C) 2006, Matt Edman, Justin Hipple
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
/**
* \file vmessagebox.h
* \version $Id: vmessagebox.h 990 2006-06-08 03:31:27Z edmanm $
*/
#ifndef _VMESSAGEBOX_H
#define _VMESSAGEBOX_H
#include <QMessageBox>
#include <QString>
class VMessageBox : public QMessageBox
{
Q_OBJECT
public:
enum Button {
NoButton = 0,
Ok,
Cancel,
Yes,
No,
Help,
Retry,
ShowLog,
ShowSettings
};
/** Default constructor. */
VMessageBox(QWidget *parent = 0);
/** Displays an critical message box with the given caption, message text,
* and visible buttons. To specify a button as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
static int critical(QWidget *parent, QString caption, QString text,
int button0, int button1 = NoButton,
int button2 = NoButton);
/** Displays an information message box with the given caption, message text,
* and visible buttons. To specify a button as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
static int information(QWidget *parent, QString caption, QString text,
int button0, int button1 = NoButton,
int button2 = NoButton);
/** Displays a warning message box with the given caption, message text, and
* visible buttons. To specify as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
static int warning(QWidget *parent, QString caption, QString text,
int button0, int button1 = NoButton,
int button2 = NoButton);
/** Displays a warning message box with the given caption, message text, and
* visible buttons. To specify as a default button or an escape
* button, OR the Button enum value with QMessageBox::Default or
* QMessageBox::Escape, respectively. */
static int question(QWidget *parent, QString caption, QString text,
int button0, int button1 = NoButton,
int button2 = NoButton);
/** Converts a Button enum value to a translated string. */
static QString buttonText(int button);
private:
/** Returns the button (0, 1, or 2) that is OR-ed with QMessageBox::Default,
* or 0 if none are. */
static int defaultButton(int button0, int button1, int button2);
/** Returns the button (0, 1, or 2) that is OR-ed with QMessageBox::Escape,
* or -1 if none are. */
static int escapeButton(int button0, int button1, int button2);
/** Returns the Button enum value from the given return value. */
static int selected(int ret, int button0, int button1, int button2);
};
#endif