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,47 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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.
****************************************************************/
#include <util/AnimatedButton.h>
//#include <util/SafeConnect.h>
//#include <util/SafeDelete.h>
#include <QtGui/QtGui>
static const char * MNG_FORMAT = "MNG";
AnimatedButton::AnimatedButton(QAbstractButton * button, const QString & animatedIconFilename) {
_button = button;
_animatedIcon = new QMovie(animatedIconFilename, MNG_FORMAT, _button);
connect(_animatedIcon, SIGNAL(frameChanged(int)), SLOT(updateButtonIcon()));
_animatedIcon->start();
}
AnimatedButton::~AnimatedButton() {
_animatedIcon->stop();
delete(_animatedIcon);
}
void AnimatedButton::updateButtonIcon() {
QPixmap icon = _animatedIcon->currentPixmap();
_button->setIcon(QIcon(icon));
_button->repaint();
}

View file

@ -0,0 +1,70 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 ANIMATEDBUTTON_H
#define ANIMATEDBUTTON_H
#include <util/rsqtutildll.h>
#include <util/NonCopyable.h>
#include <QtCore/QObject>
class QAbstractButton;
class QMovie;
class QString;
/**
* QAbstractButton with an animated icon (QMovie).
*
* Animated icon file should be a .mng file.
*
*
*/
class RSQTUTIL_API AnimatedButton : public QObject, NonCopyable {
Q_OBJECT
public:
/**
* Constructs a animated button.
*
* @param button button' icon to animate
* @param animatedIconFilename mng filename to animate the button icon
*/
AnimatedButton(QAbstractButton * button, const QString & animatedIconFilename);
~AnimatedButton();
private Q_SLOTS:
/**
* Button icon should be updated.
*/
void updateButtonIcon();
private:
QAbstractButton * _button;
QMovie * _animatedIcon;
};
#endif //ANIMATEDBUTTON_H

View file

@ -0,0 +1,37 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 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.
****************************************************************/
#include <util/EventFilter.h>
#include <QtCore/QEvent>
EventFilter::EventFilter(QObject * receiver, const char * member)
: QObject() {
connect(this, SIGNAL(activate(QEvent *)), receiver, member);
}
void EventFilter::filter(QEvent * event) {
activate(event);
}
bool EventFilter::eventFilter(QObject * watched, QEvent * event) {
return QObject::eventFilter(watched, event);
}

View file

@ -0,0 +1,84 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 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 EVENTFILTER_H
#define EVENTFILTER_H
#include <util/rsqtutildll.h>
#include <util/NonCopyable.h>
#include <QtCore/QObject>
class QEvent;
/**
* EventFilter for QObject.
*
* Permits to make some special actions on Qt events.
* Example:
* <code>
* QMainWindow * widget = new QMainWindow();
* CloseEventFilter * closeFilter = new CloseEventFilter(this, SLOT(printHelloWorld()));
* ResizeEventFilter * resizeFilter = new ResizeEventFilter(this, SLOT(printHelloWorld()));
* widget->installEventFilter(closeFilter);
* widget->installEventFilter(resizeFilter);
* </code>
*
*
*/
class RSQTUTIL_API EventFilter : public QObject, NonCopyable {
Q_OBJECT
public:
/**
* Filters an event.
*
* @param receiver object receiver of the filter signal
* @param member member of the object called by the filter signal
* @param watched watched object the filter is going to be applied on
*/
EventFilter(QObject * receiver, const char * member);
protected:
/**
* Emits the filter signal.
*
* @param event event filtered
*/
void filter(QEvent * event);
/**
* Filters the event.
*
* @param watched watched object
* @param event event filtered of the watched object
* @return true then stops the event being handled further
*/
virtual bool eventFilter(QObject * watched, QEvent * event);
Q_SIGNALS:
void activate(QEvent * event);
};
#endif //EVENTFILTER_H

View file

@ -0,0 +1,37 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 INTERFACE_H
#define INTERFACE_H
#include <util/NonCopyable.h>
/**
*
*
*/
class Interface : NonCopyable {
public:
virtual ~Interface() { }
};
#endif //INTERFACE_H

View file

@ -0,0 +1,105 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 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.
****************************************************************/
#include <util/MouseEventFilter.h>
#include <QtCore/QEvent>
#include <QtGui/QMouseEvent>
#include <exception>
MouseMoveEventFilter::MouseMoveEventFilter(QObject * receiver, const char * member)
: EventFilter(receiver, member) {
}
bool MouseMoveEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::MouseMove) {
filter(event);
return false;
}
return EventFilter::eventFilter(watched, event);
}
MousePressEventFilter::MousePressEventFilter(QObject * receiver, const char * member, Qt::MouseButton button)
: EventFilter(receiver, member),
_button(button) {
}
bool MousePressEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::MouseButtonPress) {
try {
QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *>(event);
if ((_button == Qt::NoButton) || (mouseEvent->button() == _button)) {
filter(event);
return false;
}
} catch (std::bad_cast) {
//LOG_FATAL("exception when casting a QEvent to a QMouseEvent");
}
}
return EventFilter::eventFilter(watched, event);
}
MouseReleaseEventFilter::MouseReleaseEventFilter(QObject * receiver, const char * member, Qt::MouseButton button)
: EventFilter(receiver, member),
_button(button) {
}
bool MouseReleaseEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::MouseButtonRelease) {
try {
QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *>(event);
if ((_button == Qt::NoButton) || (mouseEvent->button() == _button)) {
filter(event);
return false;
}
} catch (std::bad_cast) {
//LOG_FATAL("exception when casting a QEvent to a QMouseEvent");
}
}
return EventFilter::eventFilter(watched, event);
}
MouseHoverEnterEventFilter::MouseHoverEnterEventFilter(QObject * receiver, const char * member)
: EventFilter(receiver, member) {
}
bool MouseHoverEnterEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::HoverEnter) {
filter(event);
return false;
}
return EventFilter::eventFilter(watched, event);
}
MouseHoverLeaveEventFilter::MouseHoverLeaveEventFilter(QObject * receiver, const char * member)
: EventFilter(receiver, member) {
}
bool MouseHoverLeaveEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::HoverLeave) {
filter(event);
return false;
}
return EventFilter::eventFilter(watched, event);
}

View file

@ -0,0 +1,110 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 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 MOUSEEVENTFILTER_H
#define MOUSEEVENTFILTER_H
#include <util/EventFilter.h>
/**
* Catch MouseMove event.
*
*
*/
class RSQTUTIL_API MouseMoveEventFilter : public EventFilter {
public:
MouseMoveEventFilter(QObject * receiver, const char * member);
private:
virtual bool eventFilter(QObject * watched, QEvent * event);
};
/**
* Catch MouseButtonPress event.
*
*
*/
class RSQTUTIL_API MousePressEventFilter : public EventFilter {
public:
MousePressEventFilter(QObject * receiver, const char * member, Qt::MouseButton button = Qt::NoButton);
private:
virtual bool eventFilter(QObject * watched, QEvent * event);
Qt::MouseButton _button;
};
/**
* Catch MouseButtonRelease event.
*
*
*/
class RSQTUTIL_API MouseReleaseEventFilter : public EventFilter {
public:
MouseReleaseEventFilter(QObject * receiver, const char * member, Qt::MouseButton button = Qt::NoButton);
private:
virtual bool eventFilter(QObject * watched, QEvent * event);
Qt::MouseButton _button;
};
/**
* Catch HoverEnter event.
*
*
*/
class RSQTUTIL_API MouseHoverEnterEventFilter : public EventFilter {
public:
MouseHoverEnterEventFilter(QObject * receiver, const char * member);
private:
virtual bool eventFilter(QObject * watched, QEvent * event);
};
/**
* Catch HoverLeave event.
*
*
*/
class RSQTUTIL_API MouseHoverLeaveEventFilter : public EventFilter {
public:
MouseHoverLeaveEventFilter(QObject * receiver, const char * member);
private:
virtual bool eventFilter(QObject * watched, QEvent * event);
};
#endif //MOUSEEVENTFILTER_H

View file

@ -0,0 +1,28 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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.
****************************************************************/
#include <util/NonCopyable.h>
NonCopyable::NonCopyable() {
}
NonCopyable::~NonCopyable() {
}

View file

@ -0,0 +1,63 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 NONCOPYABLE_H
#define NONCOPYABLE_H
#include <util/rsutildll.h>
/**
* Ensures derived classes have private copy constructor and copy assignment.
*
* Example:
* <pre>
* class MyClass : NonCopyable {
* public:
* ...
* };
* </pre>
*
* Taken from Boost library.
*
* @see boost::noncopyable
*
*/
class NonCopyable {
protected:
RSUTIL_API NonCopyable();
RSUTIL_API ~NonCopyable();
private:
/**
* Copy constructor is private.
*/
NonCopyable(const NonCopyable &);
/**
* Copy assignement is private.
*/
const NonCopyable & operator=(const NonCopyable &);
};
#endif //NONCOPYABLE_H

View file

@ -0,0 +1,40 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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.
****************************************************************/
#include <util/PixmapMerging.h>
#include <QtGui/QtGui>
QPixmap PixmapMerging::merge(const std::string & foregroundPixmapData, const std::string & backgroundPixmapFilename) {
QImage foregroundImage;
foregroundImage.loadFromData((uchar *) foregroundPixmapData.c_str(), foregroundPixmapData.size());
QPixmap backgroundPixmap = QPixmap(QString::fromStdString(backgroundPixmapFilename));
if (!foregroundImage.isNull()) {
QPainter painter(&backgroundPixmap);
painter.drawImage(0, 0,
foregroundImage.scaled(backgroundPixmap.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
painter.end();
}
return backgroundPixmap;
}

View file

@ -0,0 +1,53 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 PIXMAPMERGING_H
#define PIXMAPMERGING_H
#include <util/rsqtutildll.h>
#include <util/NonCopyable.h>
#include <string>
class QPixmap;
/**
* Merges 2 pixmaps together.
*
*
*/
class PixmapMerging : NonCopyable {
public:
/**
* Merges 2 pixmaps together.
*
* Used to have a background picture (a cadre) and a picture inside it.
* Currently used to a the avatar of a contact inside a nice background.
*
* @param foregroundPixmapData an 'array' with the foreground picture data
* @param backgroundPixmapFilename background pixmap filename e.g ":/pics/avatar_background.png"
*/
RSQTUTIL_API static QPixmap merge(const std::string & foregroundPixmapData, const std::string & backgroundPixmapFilename);
};
#endif //PIXMAPMERGING_H

View file

@ -0,0 +1,215 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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.
****************************************************************/
#include <util/RetroStyleLabel.h>
#include <QtGui/QtGui>
RetroStyleLabel::RetroStyleLabel(QWidget * parent, Mode mode, Qt::AlignmentFlag hAlign)
: QLabel(parent), _mode(mode) {
_parent = parent;
_pressed = false;
_selected = false;
_toggled = false;
//Default background color
_backgroundColor = _parent->palette().color(QPalette::Window);
//Default text color
_textColor = _parent->palette().color(QPalette::Text);
_alignment = Qt::AlignVCenter | hAlign;
}
RetroStyleLabel::~RetroStyleLabel() {
}
void RetroStyleLabel::paintEvent(QPaintEvent * event) {
/*
qDebug() << "Paint event";
QLabel::paintEvent( event );
return;
*/
QRect rect = this->rect();
QPainter painter(this);
rect.adjust(-1, -1, 1, 1);
//painter.fillRect(rect,QBrush(_backgroundColor));
if (!_pressed && !_selected) {
//Draw the left side if any
if (!_normalLeftPixmap.isNull()) {
painter.drawPixmap(0,0,_normalLeftPixmap);
}
//Fill the the label
if (!_normalFillPixmap.isNull()) {
QBrush brush(_normalFillPixmap);
QRect fillRect = rect;
if (!_normalLeftPixmap.isNull()) {
fillRect.adjust(_normalLeftPixmap.rect().width()-1,0,0,0);
}
if (!_normalRightPixmap.isNull()) {
fillRect.adjust(0,0,0-_normalRightPixmap.rect().width(),0);
}
painter.fillRect(fillRect,brush);
}
//Draw the right side
if (!_normalRightPixmap.isNull()) {
painter.drawPixmap( (rect.width()-1) - _normalRightPixmap.rect().width(),0,_normalRightPixmap);
}
} //if (! _pressed )
else {
//Draw the left side if any
if (!_pressedLeftPixmap.isNull()) {
painter.drawPixmap(0, 0, _pressedLeftPixmap);
}
//Fill the the label
if (!_pressedFillPixmap.isNull()) {
QBrush brush(_pressedFillPixmap);
QRect fillRect = rect;
if (!_pressedLeftPixmap.isNull()) {
fillRect.adjust(_pressedLeftPixmap.rect().width() - 1, 0, 0, 0);
}
if (!_pressedRightPixmap.isNull()) {
fillRect.adjust(0, 0, 0 - _pressedRightPixmap.rect().width(), 0);
}
painter.fillRect(fillRect,brush);
}
//Draw the right side
if (!_pressedRightPixmap.isNull()) {
painter.drawPixmap((rect.width() - 1) - _pressedRightPixmap.rect().width(), 0, _pressedRightPixmap);
}
}
painter.end();
QPainter p(this);
drawText(&p);
p.end();
}
void RetroStyleLabel::drawText(QPainter * painter) {
QRect rect = this->rect();
painter->save();
painter->setPen(_textColor);
painter->drawText(rect, _alignment, this->text(), &rect);
painter->restore();
}
void RetroStyleLabel::resizeEvent ( QResizeEvent * event) {
QLabel::resizeEvent(event);
}
void RetroStyleLabel::setPixmaps(const QPixmap & normalLeftPixmap,
const QPixmap & normalRightPixmap,
const QPixmap & normalFillPixmap,
const QPixmap & pressedLeftPixmap,
const QPixmap & pressedRightPixmap,
const QPixmap & pressedFillPixmap) {
_normalLeftPixmap = normalLeftPixmap;
_normalRightPixmap = normalRightPixmap;
_normalFillPixmap = normalFillPixmap;
_pressedLeftPixmap = pressedLeftPixmap;
_pressedRightPixmap = pressedRightPixmap;
_pressedFillPixmap = pressedFillPixmap;
}
/*void RetroStyleLabel::setLeftPixmaps(const QPixmap & normalLeftPixmap, const QPixmap & pressedLeftPixmap) {
_normalLeftPixmap = normalLeftPixmap;
_pressedLeftPixmap = pressedLeftPixmap;
}
void RetroStyleLabel::setRightPixmaps(const QPixmap & normalRightPixmap, const QPixmap & pressedRightPixmap) {
_normalRightPixmap = normalRightPixmap;
_pressedRightPixmap = pressedRightPixmap;
}*/
void RetroStyleLabel::setTextColor(const QColor & color) {
_textColor = color;
}
/*void RetroStyleLabel::setBackgroundColor(const QColor & color) {
_backgroundColor = color;
}*/
void RetroStyleLabel::mouseMoveEvent(QMouseEvent * event) {
_pressed = false;
QPoint mousePosition = event->pos();
const QRect rect = this->rect();
if ((mousePosition.x() >= rect.x()) && ( mousePosition.x() <= rect.width())) {
if ((mousePosition.y() >= rect.y()) && ( mousePosition.y() <= rect.height())) {
_pressed = true;
}
}
update();
}
void RetroStyleLabel::mousePressEvent(QMouseEvent * event) {
if (event->button() == Qt::LeftButton) {
_pressed = true;
update();
}
}
void RetroStyleLabel::mouseReleaseEvent(QMouseEvent * event) {
if (!_pressed) {
return;
}
//Gets the widget rect
const QRect rect = this->rect();
//Gets the mouse position relative to this widget
QPoint mousePosition = event->pos();
if ((mousePosition.x() >= rect.x()) && (mousePosition.x() <= rect.width())) {
if ((mousePosition.y() >= rect.y()) && (mousePosition.y() <= rect.height())) {
clicked();
if (_mode == Toggled) {
_toggled = !_toggled;
if (_toggled) {
_pressed = true;
} else {
_pressed = false;
}
} else {
_pressed = false;
}
update();
}
}
}
void RetroStyleLabel::setText(const QString & text) {
QLabel::setText(text);
QFontMetrics fm(font());
int textWidth = fm.width(text);
textWidth += 40;
QSize s = size();
if (textWidth > s.width()) {
//setMaximumSize(textWidth,s.height());
setMinimumSize(textWidth,s.height());
}
}

View file

@ -0,0 +1,119 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 RETROSTYLELABEL_H
#define RETROSTYLELABEL_H
#include <util/rsqtutildll.h>
#include <QtGui/QLabel>
#include <QtGui/QPixmap>
#include <QtGui/QColor>
class RSQTUTIL_API RetroStyleLabel : public QLabel {
Q_OBJECT
public:
enum Mode {
Normal,
Toggled,
};
RetroStyleLabel(QWidget * parent, Mode = Normal, Qt::AlignmentFlag hAlign = Qt::AlignHCenter);
~RetroStyleLabel();
void setPixmaps(const QPixmap & normalLeftPixmap,
const QPixmap & normalRightPixmap,
const QPixmap & normalFillPixmap,
const QPixmap & pressedLeftPixmap,
const QPixmap & pressedRightPixmap,
const QPixmap & pressedFillPixmap);
/*void setLeftPixmaps(const QPixmap & normalRightPixmap, const QPixmap & pressedRightPixmap);
void setRightPixmaps(const QPixmap & normalRightPixmap, const QPixmap & pressedRightPixmap);*/
void setTextColor(const QColor & color);
//void setBackgroundColor(const QColor & color);
void setTextAlignment(int alignment) {
_alignment = alignment;
}
void setSelected(bool value) {
_selected = value;
}
public Q_SLOTS:
void setText(const QString & text);
Q_SIGNALS:
void clicked();
private:
void paintEvent(QPaintEvent * event);
void resizeEvent(QResizeEvent * event);
void drawText(QPainter * painter);
void mouseMoveEvent(QMouseEvent * event);
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);
QPixmap _normalFillPixmap;
QPixmap _normalLeftPixmap;
QPixmap _normalRightPixmap;
QPixmap _pressedFillPixmap;
QPixmap _pressedLeftPixmap;
QPixmap _pressedRightPixmap;
QColor _textColor;
QColor _backgroundColor;
bool _pressed;
bool _selected;
QWidget * _parent;
int _alignment;
bool _toggled;
Mode _mode;
};
#endif //RETROSTYLELABEL_H

View file

@ -0,0 +1,50 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2007 DrBob
*
* 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 "util/RsAction.h"
RsAction::RsAction(QWidget * parent, std::string rsid)
: QAction(parent), RsId(rsid)
{
connect(this, SIGNAL( triggered( bool ) ), this, SLOT( triggerEvent( bool ) ) );
}
RsAction::RsAction(const QString & text, QObject * parent, std::string rsid)
: QAction(text, parent), RsId(rsid)
{
connect(this, SIGNAL( triggered( bool ) ), this, SLOT( triggerEvent( bool ) ) );
}
RsAction::RsAction(const QIcon & icon, const QString & text, QObject * parent , std::string rsid)
: QAction(icon, text, parent), RsId(rsid)
{
connect(this, SIGNAL( triggered( bool ) ), this, SLOT( triggerEvent( bool ) ) );
}
void RsAction::triggerEvent( bool checked )
{
triggeredId(RsId);
}
//void triggeredId( std::string rsid );

View file

@ -0,0 +1,50 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2007 drbob
*
* 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 RETRO_ACTION_H
#define RETRO_ACTION_H
#include <QAction>
class RsAction : public QAction {
Q_OBJECT
public:
RsAction(QWidget * parent, std::string rsid);
RsAction(const QString & text, QObject * parent, std::string rsid);
RsAction(const QIcon & icon, const QString & text, QObject * parent , std::string rsid);
public Q_SLOTS:
/* attached to triggered() -> calls triggeredId() */
void triggerEvent( bool checked );
Q_SIGNALS:
void triggeredId( std::string rsid );
private:
std::string RsId;
};
#endif //RETRO_ACTION_H

View file

@ -0,0 +1,38 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 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.
****************************************************************/
#include <util/Widget.h>
#include <QtGui/QtGui>
QGridLayout * Widget::createLayout(QWidget * parent) {
QGridLayout * layout = new QGridLayout(parent);
layout->setSpacing(0);
layout->setMargin(0);
return layout;
}
QDialog * Widget::transformToWindow(QWidget * widget) {
QDialog * dialog = new QDialog(widget->parentWidget());
widget->setParent(NULL);
createLayout(dialog)->addWidget(widget);
return dialog;
}

View file

@ -0,0 +1,58 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 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 RSWIDGET_H
#define RSWIDGET_H
#include <util/rsqtutildll.h>
#include <util/NonCopyable.h>
class QWidget;
class QGridLayout;
class QDialog;
/**
* Helper functions for QWidget.
*
*
*/
class Widget : NonCopyable {
public:
/**
* Creates a QGridLayout inside a widget.
*
* @param parent QWidget where to create the layout
* @return QGridLayout
*/
RSQTUTIL_API static QGridLayout * createLayout(QWidget * parent);
/**
* Transforms a QWidget into a QDialog.
*
* @param widget QWidget to transform into a QDialog
* @return the QDialog created
*/
RSQTUTIL_API static QDialog * transformToWindow(QWidget * widget);
};
#endif //RSWIDGET_H

View file

@ -0,0 +1,53 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 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.
****************************************************************/
#include <util/WidgetBackgroundImage.h>
#include <QtCore/QString>
#include <QtGui/QWidget>
#include <QtGui/QPixmap>
#include <QtGui/QPalette>
#include <QtGui/QBrush>
void WidgetBackgroundImage::setBackgroundImage(QWidget * widget, const char * imageFile, WidgetBackgroundImage::AdjustMode adjustMode) {
widget->setAutoFillBackground(true);
QPixmap pixmap(imageFile);
switch (adjustMode) {
case AdjustNone:
break;
case AdjustWidth:
widget->setMinimumWidth(pixmap.width());
break;
case AdjustHeight:
widget->setMinimumHeight(pixmap.height());
break;
case AdjustSize:
widget->resize(pixmap.size());
widget->setMinimumSize(pixmap.size());
break;
}
QPalette palette = widget->palette();
palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
widget->setPalette(palette);
}

View file

@ -0,0 +1,58 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 WIDGETBACKGROUNDIMAGE_H
#define WIDGETBACKGROUNDIMAGE_H
#include <util/rsqtutildll.h>
#include <util/NonCopyable.h>
class QWidget;
/**
* Replacement for QWidget::setBackgroundPixmap() that does not exist in Qt4 anymore.
*
* Draws a background image inside a QWidget.
*
*
*/
class WidgetBackgroundImage : NonCopyable {
public:
enum AdjustMode {
AdjustNone,
AdjustWidth,
AdjustHeight,
AdjustSize
};
/**
* Sets a background image to a QWidget.
*
* @param widget QWidget that will get the background image
* @param imageFile background image filename
* @param adjustMode whether we should adjust the image width, height or
* both
*/
RSQTUTIL_API static void setBackgroundImage(QWidget * widget, const char * imageFile, AdjustMode adjustMode);
};
#endif //WIDGETBACKGROUNDIMAGE_H

View file

@ -0,0 +1,84 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 DLLEXPORT_H
#define DLLEXPORT_H
#include <util/global.h>
/**
* @file dllexport.h
*
* Header that export symbols for creating a .dll under Windows.
* Example:
* <pre>
* #ifdef MY_DLL
* #ifdef BUILDING_DLL
* #define API DLLEXPORT
* #else
* #define API DLLIMPORT
* #endif
* #else
* #define API
* #endif
*
* class API MyClass
* API int publicFunction()
* class EXCEPTIONAPI(API) PublicThrowableClass
* class DLLLOCAL MyClass
* </pre>
*
* You should define DLL if you want to use the library as a shared one
* + when you build the library you should define BUILDING_DLL
* GCC > v4.0 support library visibility attributes.
*
* @see http://gcc.gnu.org/wiki/Visibility
*
*/
//Shared library support
#ifdef OS_WIN32
#define DLLIMPORT __declspec(dllimport)
#define DLLEXPORT __declspec(dllexport)
#define DLLLOCAL
#define DLLPUBLIC
#else
#define DLLIMPORT
#ifdef CC_GCC4
#define DLLEXPORT __attribute__ ((visibility("default")))
#define DLLLOCAL __attribute__ ((visibility("hidden")))
#define DLLPUBLIC __attribute__ ((visibility("default")))
#else
#define DLLEXPORT
#define DLLLOCAL
#define DLLPUBLIC
#endif
#endif
//Throwable classes must always be visible on GCC in all binaries
#ifdef OS_WIN32
#define EXCEPTIONAPI(api) api
#elif defined(GCC_HASCLASSVISIBILITY)
#define EXCEPTIONAPI(api) DLLEXPORT
#else
#define EXCEPTIONAPI(api)
#endif
#endif //DLLEXPORT_H

View file

@ -0,0 +1,152 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 RSGLOBAL_H
#define RSGLOBAL_H
/**
* OS and compilers detection via defines (preprocessor).
*
* Most of this defines are from Qt (Trolltech).
* In each category (OS_ and CC_) one define exludes the others.
* Warning: if you want to add a define to this file, the order is very important.
*
* Operating systems:
* - OS_WINDOWS
* - OS_WIN32
* - OS_WIN64
* - OS_WINCE_POCKETPC (Windows CE for PocketPC)
* - OS_WINCE_SMARTPHONE (Windows CE for smartphone)
* - OS_POSIX
* - OS_MACOSX
* - OS_LINUX
* - OS_HURD
* - OS_BSD
* - OS_FREEBSD
* - OS_NETBSD
* - OS_OPENBSD
*
* Compilers:
* - CC_MSVC (Microsoft Visual C++)
* - CC_MSVC6 (Visual C++ 6)
* - CC_MSVC7 (Visual C++ .NET)
* - CC_MSVC71 (Visual C++ 2003)
* - CC_MSVC8 (Visual C++ 2005)
* - CC_WINCE (Microsoft Visual C++ Embedded for Windows CE)
* - CC_WINCE1 (Windows CE 1.x)
* - CC_WINCE2 (Windows CE 2.x)
* - CC_WINCE3 (Windows CE 3.x)
* - CC_WINCE4 (Windows CE 4.x)
* - CC_WINCE5 (Windows CE 5.x)
* - CC_GCC
* - CC_MINGW (Native GCC under Windows)
* - CC_GCC3 (GNU GCC 3.x)
* - CC_GCC4 (GNU GCC 4.x)
* - CC_INTEL (Intel C++)
* - CC_BORLAND (Borland C++)
*
* @file global.h
* @see qglobal.h from Qt4
*
*/
//OS
#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
#define OS_MACOSX
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#define OS_WIN32
#elif defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
#define OS_WIN64
#elif defined(__linux__) || defined(__linux)
#define OS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#define OS_FREEBSD
#elif defined(__NetBSD__)
#define OS_NETBSD
#elif defined(__OpenBSD__)
#define OS_OPENBSD
#elif defined(__GNU_HURD__)
#define OS_HURD
#elif defined(WIN32_PLATFORM_PSPC)
#define OS_WINCE_POCKETPC
#elif defined(WIN32_PLATFORM_WFSP)
#define OS_WINCE_SMARTPHONE
#else
#error This OS has not been tested
#endif
#if defined(OS_WIN32) || defined(OS_WIN64) || defined(OS_WINCE_POCKETPC) || defined(OS_WINCE_SMARTPHONE)
#define OS_WINDOWS
#endif
#if defined(OS_FREEBSD) || defined(OS_NETBSD) || defined(OS_OPENBSD)
#define OS_BSD
#endif
#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_HURD) || defined(OS_BSD)
#define OS_POSIX
#endif
//Compilers
#if defined(__INTEL_COMPILER)
#define CC_INTEL
#elif defined(_MSC_VER)
#define CC_MSVC
#if _MSC_VER <= 1200
#define CC_MSVC6
#elif _MSC_VER <= 1300
#define CC_MSVC7
#elif _MSC_VER <= 1310
#define CC_MSVC71
#elif _MSC_VER <= 1400
#define CC_MSVC8
#endif
#elif defined(_WIN32_WCE)
#define CC_WINCE
#if _WIN32_WCE <= 101
#define CC_WINCE1
#elif _WIN32_WCE <= 211
#define CC_WINCE2
#elif _WIN32_WCE <= 300
#define CC_WINCE3
#elif _WIN32_WCE <= 400
#define CC_WINCE4
#elif _WIN32_WCE <= 500
#define CC_WINCE5
#endif
#elif defined(__GNUC__)
#define CC_GCC
#if __GNUC__ == 3
#define CC_GCC3
#elif _MSC_VER == 4
#define CC_GCC4
#endif
#if defined(__MINGW32__)
#define CC_MINGW
#endif
#elif defined(__BORLANDC__) || defined(__TURBOC__)
#define CC_BORLAND
#else
#error This compiler has not been tested
#endif
#endif //OWGLOBAL_H

View file

@ -0,0 +1,123 @@
/****************************************************************
* RShare 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 <QDir>
#include <QFile>
#include <QTextStream>
#include "string.h"
#include "process.h"
/** Returns the PID of the current process. */
qint64
get_pid()
{
#if defined(Q_OS_WIN)
return (qint64)GetCurrentProcessId();
#else
return (qint64)getpid();
#endif
}
/** Returns true if a process with the given PID is running. */
bool
is_process_running(qint64 pid)
{
#if defined(Q_OS_WIN)
BOOL rc;
DWORD exitCode;
/* Try to open the process to see if it exists */
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, (DWORD)pid);
if (hProcess == NULL) {
return false;
}
/* It exists, so see if it's still active or if it terminated already */
rc = GetExitCodeProcess(hProcess, &exitCode);
CloseHandle(hProcess);
if (!rc) {
/* Error. Assume it doesn't exist (is this a bad assumption?) */
return false;
}
/* If GetExitCodeProcess() returns a non-zero value, and the process is
* still running, exitCode should equal STILL_ACTIVE. Otherwise, this means
* the process has terminated. */
return (exitCode == STILL_ACTIVE);
#else
/* Send the "null" signal to check if a process exists */
if (kill((pid_t)pid, 0) < 0) {
return (errno != ESRCH);
}
return true;
#endif
}
/** Writes the given file to disk containing the current process's PID. */
bool
write_pidfile(QString pidFileName, QString *errmsg)
{
/* Make sure the directory exists */
QDir pidFileDir = QFileInfo(pidFileName).absoluteDir();
if (!pidFileDir.exists()) {
pidFileDir.mkpath(QDir::convertSeparators(pidFileDir.absolutePath()));
}
/* Try to open (and create if it doesn't exist) the pidfile */
QFile pidfile(pidFileName);
if (!pidfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
return err(errmsg, pidfile.errorString());
}
/* Write our current PID to it */
QTextStream pidstream(&pidfile);
pidstream << get_pid();
return true;
}
/** Reads the given pidfile and returns the value contained in it. If the file
* does not exist 0 is returned. Returns -1 if an error occurs. */
qint64
read_pidfile(QString pidFileName, QString *errmsg)
{
qint64 pid;
/* Open the pidfile, if it exists */
QFile pidfile(pidFileName);
if (!pidfile.exists()) {
return 0;
}
if (!pidfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (errmsg) {
*errmsg = pidfile.errorString();
}
return -1;
}
/* Read the PID in from the file */
QTextStream pidstream(&pidfile);
pidstream >> pid;
return pid;
}

View file

@ -0,0 +1,53 @@
/****************************************************************
* RShare 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.
****************************************************************/
#ifndef _PROCESS_H
#define _PROCESS_H
#include <QString>
#if defined(Q_OS_WIN)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#endif
/** Returns the PID of the current process. */
qint64 get_pid();
/** Returns true if a process with the given PID is running. */
bool is_process_running(qint64 pid);
/** Writes the given file to disk containing the current process's PID. */
bool write_pidfile(QString pidfile, QString *errmsg = 0);
/** Reads the giiven pidfile and returns the value in it. If the file does not
* exist, -1 is returned. */
qint64 read_pidfile(QString pidfile, QString *errmsg = 0);
#endif

View file

@ -0,0 +1,110 @@
/****************************************************************
* RShare 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 "registry.h"
/** Returns the value in keyName at keyLocation.
* Returns an empty QString if the keyName doesn't exist */
QString
registry_get_key_value(QString keyLocation, QString keyName)
{
#if 0
HKEY key;
char data[255] = {0};
DWORD size = sizeof(data);
/* Open the key for reading (opens new key if it doesn't exist) */
if (RegOpenKeyExA(HKEY_CURRENT_USER,
qPrintable(keyLocation),
0L, KEY_READ, &key) == ERROR_SUCCESS) {
/* Key exists, so read the value into data */
RegQueryValueExA(key, qPrintable(keyName),
NULL, NULL, (LPBYTE)data, &size);
}
/* Close anything that was opened */
RegCloseKey(key);
return QString(data);
#endif
return keyName;
}
/** Creates and/or sets the key to the specified value */
void
registry_set_key_value(QString keyLocation, QString keyName, QString keyValue)
{
#if 0
HKEY key;
/* Open the key for writing (opens new key if it doesn't exist */
if (RegOpenKeyExA(HKEY_CURRENT_USER,
qPrintable(keyLocation),
0, KEY_WRITE, &key) != ERROR_SUCCESS) {
/* Key didn't exist, so write the newly opened key */
RegCreateKeyExA(HKEY_CURRENT_USER,
qPrintable(keyLocation),
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&key, NULL);
}
/* Save the value in the key */
RegSetValueExA(key, qPrintable(keyName), 0, REG_SZ,
(BYTE *)qPrintable(keyValue),
(DWORD)keyValue.length() + 1); // include null terminator
/* Close the key */
RegCloseKey(key);
#endif
}
/** Removes the key from the registry if it exists */
void
registry_remove_key(QString keyLocation, QString keyName)
{
#if 0
HKEY key;
/* Open the key for writing (opens new key if it doesn't exist */
if (RegOpenKeyExA(HKEY_CURRENT_USER,
qPrintable(keyLocation),
0, KEY_SET_VALUE, &key) == ERROR_SUCCESS) {
/* Key exists so delete it */
RegDeleteValueA(key, qPrintable(keyName));
}
/* Close anything that was opened */
RegCloseKey(key);
#endif
}

View file

@ -0,0 +1,46 @@
/****************************************************************
* Vidalia 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.
****************************************************************/
#ifndef _REGISTRY_H
#define _REGISTRY_H
#include <QString>
#define WIN32_LEAN_AND_MEAN
#if 0
#include "windows.h"
#endif
/** Returns value of keyName or empty QString if keyName doesn't exist */
QString registry_get_key_value(QString keyLocation, QString keyName);
/** Creates and/or sets the key to the specified value */
void registry_set_key_value(QString keyLocation, QString keyName, QString keyValue);
/** Removes the key from the registry if it exists */
void registry_remove_key(QString keyLocation, QString keyName);
#endif

View file

@ -0,0 +1,37 @@
/****************************************************************
* 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.
****************************************************************/
#ifndef RSQTUTILDLL_H
#define RSQTUTILDLL_H
#include <util/dllexport.h>
#ifdef RSQTUTIL_DLL
#ifdef BUILD_RSQTUTIL_DLL
#define RSQTUTIL_API DLLEXPORT
#else
#define RSQTUTIL_API DLLIMPORT
#endif
#else
#define RSQTUTIL_API
#endif
#endif //RSQTUTILDLL_H

View file

@ -0,0 +1,37 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 RSUTILDLL_H
#define RSUTILDLL_H
#include <util/dllexport.h>
#ifdef RSUTIL_DLL
#ifdef BUILD_RSUTIL_DLL
#define RSUTIL_API DLLEXPORT
#else
#define RSUTIL_API DLLIMPORT
#endif
#else
#define RSUTIL_API
#endif
#endif //RSUTILDLL_H

View file

@ -0,0 +1,38 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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.
****************************************************************/
#include "rsversion.h"
//#define USE_SVN_VERSIONS 1
#define VERSION "0.3.52a"
#if USE_SVN_VERSIONS
#include "svn_revision.h"
#endif
QString retroshareVersion() {
#if USE_SVN_VERSIONS
return QString(QString(VERSION) + "+" + QString(SVN_REVISION));
#else
return QString(VERSION);
#endif
}

View file

@ -0,0 +1,30 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,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 _RSVERSION_H_
#define _RSVERSION_H_
#include <QString>
QString retroshareVersion();
#endif

View file

@ -0,0 +1,65 @@
/****************************************************************
* Vidalia 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 "string.h"
/** Create a QStringList from the array of C-style strings. */
QStringList
char_array_to_stringlist(char **arr, int len)
{
QStringList list;
for (int i = 0; i < len; i++) {
list << QString(arr[i]);
}
return list;
}
/** Conditionally assigns errmsg to str if str is not null and returns false.
* This is a seemingly pointless function, but it saves some messiness in
* methods whose QString *errmsg parameter is optional. */
bool
err(QString *str, QString errmsg)
{
if (str) {
*str = errmsg;
}
return false;
}
/** Ensures all characters in str are in validChars. If a character appears
* in str but not in validChars, it will be removed and the resulting
* string returned. */
QString
ensure_valid_chars(QString str, QString validChars)
{
QString out = str;
for (int i = 0; i < str.length(); i++) {
QChar c = str.at(i);
if (validChars.indexOf(c) < 0) {
out.remove(c);
}
}
return out;
}

View file

@ -0,0 +1,42 @@
/****************************************************************
* Vidalia 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.
****************************************************************/
#ifndef __STRING_H
#define __STRING_H
#include <QStringList>
/** Creates a QStringList from the array of C strings. */
QStringList char_array_to_stringlist(char **arr, int len);
/** Ensures all characters in str are in validChars. If a character appears
* in str but not in validChars, it will be removed and the resulting
* string returned. */
QString ensure_valid_chars(QString str, QString validChars);
/** Conditionally assigns errmsg to string if str is not null and returns
* false. */
bool err(QString *str, QString errmsg);
#endif

View file

@ -0,0 +1,82 @@
/****************************************************************
* RShare 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.
****************************************************************/
#if 0
#include <windows.h>
#include <shlobj.h>
#endif
#include <QDir>
#include "win32.h"
/** Finds the location of the "special" Windows folder using the given CSIDL
* value. If the folder cannot be found, the given default path is used. */
QString
win32_get_folder_location(int folder, QString defaultPath)
{
#if 0
TCHAR path[MAX_PATH+1];
LPITEMIDLIST idl;
IMalloc *m;
HRESULT result;
/* Find the location of %PROGRAMFILES% */
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, folder, &idl))) {
/* Get the path from the IDL */
result = SHGetPathFromIDList(idl, path);
SHGetMalloc(&m);
if (m) {
m->Release();
}
if (SUCCEEDED(result)) {
QT_WA(return QString::fromUtf16((const ushort *)path);,
return QString::fromLocal8Bit((char *)path);)
}
}
#endif
return defaultPath;
}
/** Gets the location of the user's %PROGRAMFILES% folder. */
QString
win32_program_files_folder()
{
return win32_get_folder_location(
#if 0
CSIDL_PROGRAM_FILES, QDir::rootPath() + "\\Program Files");
#endif
0, QDir::rootPath() + "\\Program Files");
}
/** Gets the location of the user's %APPDATA% folder. */
QString
win32_app_data_folder()
{
return win32_get_folder_location(
#if 0
CSIDL_APPDATA, QDir::homePath() + "\\Application Data");
#endif
0, QDir::homePath() + "\\Application Data");
}

View file

@ -0,0 +1,35 @@
/****************************************************************
* RShare 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.
****************************************************************/
#ifndef _WIN32_H
#define _WIN32_H
#include <QString>
/** Retrieves the location of the user's %PROGRAMFILES% folder. */
QString win32_program_files_folder();
/** Retrieves the location of the user's %APPDATA% folder. */
QString win32_app_data_folder();
#endif