There is still some work left concerning menu states, progress bar, and the dialog,
and also we don't have user management yet (so you have to use user "Default" and
password "password" for both internal and external cores), but basically it's working.
This also (finally!) closes BR #17.
src/client/clientsettings.cpp
src/qtgui/guisettings.h
src/qtgui/guisettings.cpp
+src/common/ircuser.h
+src/common/ircuser.cpp
#ENDIF(BUILD_CORE OR BUILD_QTGUI)
SET(CMAKE_BUILD_TYPE Debug)
+SET(GCC_WARN "-Wall -Wextra -ansi -Wno-unused-parameter") # may not be portable!
# Define files
SET(quassel_mono_SRCS common/build_mono.cpp)
SET(QT_DONT_USE_QTGUI true) # This is added later if GUI is requested
INCLUDE(${QT_USE_FILE})
+ADD_DEFINITIONS(${GCC_WARN})
+
# Define subdirs. CMake complains if a directory is added twice, so make sure this
# does not happen in any combination of the requested targets.
QT4_ADD_RESOURCES(_RCCS ${quassel_RCCS})
-ADD_DEFINITIONS(-Wall -Wextra -ansi) # may not be portable!
-
SET(TARGET_LIST )
IF(BUILD_CORE)
SET(client_MOCS buffer.h buffertreemodel.h client.h clientproxy.h clientsettings.h treemodel.h)
QT4_WRAP_CPP(_MOC ${client_MOCS})
+
ADD_LIBRARY(client ${client_SRCS} ${_MOC})
TARGET_LINK_LIBRARIES(client common)
\ No newline at end of file
blockSize = 0;
connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
- connect(&socket, SIGNAL(connected()), this, SLOT(coreConnected()));
- connect(&socket, SIGNAL(disconnected()), this, SLOT(coreDisconnected()));
+ connect(&socket, SIGNAL(connected()), this, SLOT(coreSocketConnected()));
+ connect(&socket, SIGNAL(disconnected()), this, SLOT(coreSocketDisconnected()));
connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
connect(this, SIGNAL(sendSessionData(const QString &, const QVariant &)), clientProxy, SLOT(gsSessionDataChanged(const QString &, const QVariant &)));
connect(clientProxy, SIGNAL(csSessionDataChanged(const QString &, const QVariant &)), this, SLOT(recvSessionData(const QString &, const QVariant &)));
connect(clientProxy, SIGNAL(send(ClientSignal, QVariant, QVariant, QVariant)), this, SLOT(recvProxySignal(ClientSignal, QVariant, QVariant, QVariant)));
+ connect(clientProxy, SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(const QVariant &)));
connect(clientProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
connect(clientProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
connect(clientProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
}
if(conn["Host"].toString().isEmpty()) {
clientMode = LocalCore;
- syncToCore();
+ QVariant state = connectToLocalCore(coreConnectionInfo["User"].toString(), coreConnectionInfo["Password"].toString());
+ syncToCore(state);
} else {
clientMode = RemoteCore;
emit coreConnectionMsg(tr("Connecting..."));
socket.close();
} else {
disconnectFromLocalCore();
- coreDisconnected();
+ coreSocketDisconnected();
}
/* Clear internal data. Hopefully nothing relies on it at this point. */
coreConnectionInfo.clear();
qDebug() << "foobar";
}
-void Client::coreConnected() {
- syncToCore();
-
+void Client::coreSocketConnected() {
+ VarMap clientInit;
+ clientInit["GuiProtocol"] = GUI_PROTOCOL;
+ clientInit["User"] = coreConnectionInfo["User"].toString();
+ clientInit["Password"] = coreConnectionInfo["Password"].toString();
+ writeDataToDevice(&socket, clientInit);
}
-void Client::coreDisconnected() {
+void Client::coreSocketDisconnected() {
connectedToCore = false;
emit disconnected();
}
-void Client::syncToCore() {
- VarMap state;
- if(clientMode == LocalCore) {
- state = connectToLocalCore(coreConnectionInfo["User"].toString(), coreConnectionInfo["Password"].toString()).toMap();
- } else {
- // TODO connect to remote cores
- }
+void Client::recvCoreState(const QVariant &state) {
+ syncToCore(state);
- VarMap sessionState = state["SessionState"].toMap();
+}
+
+void Client::syncToCore(const QVariant &coreState) {
+ VarMap sessionState = coreState.toMap()["SessionState"].toMap();
VarMap sessData = sessionState["SessionData"].toMap();
+
foreach(QString key, sessData.keys()) {
recvSessionData(key, sessData[key]);
}
static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant());
static QStringList sessionDataKeys();
+ enum ClientMode { LocalCore, RemoteCore };
+ static ClientMode clientMode;
+
signals:
void sendInput(BufferId, QString message);
void showBuffer(Buffer *);
void disconnectFromCore();
private slots:
+ void recvCoreState(const QVariant &state);
void recvSessionData(const QString &key, const QVariant &data);
void recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3);
void serverError(QAbstractSocket::SocketError);
void serverHasData();
- void coreConnected();
- void coreDisconnected();
+ void coreSocketConnected();
+ void coreSocketDisconnected();
void userInput(BufferId, QString);
void networkConnected(QString);
void init();
static Client *instanceptr;
- void syncToCore();
+ void syncToCore(const QVariant &coreState);
QVariant connectToLocalCore(QString user, QString passwd); // defined in main.cpp
void disconnectFromLocalCore(); // defined in main.cpp
- enum ClientMode { LocalCore, RemoteCore };
- static ClientMode clientMode;
-
AbstractUi *mainUi;
ClientProxy *clientProxy;
BufferTreeModel *_bufferModel;
/**************************************************************************************/
-
-
BufferId::BufferId(uint _id, QString _net, QString _buf, uint _gid) : id(_id), gid(_gid), net(_net), buf(_buf) {
QDataStream &operator<<(QDataStream &out, const BufferId &bufferId) {
out << bufferId.id << bufferId.gid << bufferId.net.toUtf8() << bufferId.buf.toUtf8();
+ return out;
}
QDataStream &operator>>(QDataStream &in, BufferId &bufferId) {
QByteArray n, b;
- BufferId i;
in >> bufferId.id >> bufferId.gid >> n >> b;
bufferId.net = QString::fromUtf8(n);
bufferId.buf = QString::fromUtf8(b);
+ return in;
}
uint qHash(const BufferId &bid) {
#if defined BUILD_CORE
#include <QCoreApplication>
+#include <QDir>
#include "core.h"
#elif defined BUILD_QTGUI
#endif
int main(int argc, char **argv) {
+ qRegisterMetaType<Message>("Message");
+ qRegisterMetaType<BufferId>("BufferId");
+ qRegisterMetaTypeStreamOperators<Message>("Message");
+ qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
+
#if defined BUILD_CORE
Global::runMode = Global::CoreOnly;
QCoreApplication app(argc, argv);
#include <QDataStream>
QDataStream &operator<<(QDataStream &out, const Message &msg) {
- /*
- out << (quint32)msg.timeStamp.toTime_t() << (quint8)msg.type << (quint8)msg.flags
- << msg.target.toUtf8() << msg.sender.toUtf8() << msg.text.toUtf8();
- */
out << (quint32)msg.timeStamp.toTime_t() << (quint8)msg.type << (quint8)msg.flags
<< msg.buffer << msg.sender.toUtf8() << msg.text.toUtf8();
return out;
QDataStream &operator>>(QDataStream &in, Message &msg) {
quint8 t, f;
quint32 ts;
- QByteArray s, m, targ;
+ QByteArray s, m;
BufferId buf;
in >> ts >> t >> f >> buf >> s >> m;
msg.type = (Message::Type)t;
msg.flags = (quint8)f;
+ msg.buffer = buf;
msg.timeStamp = QDateTime::fromTime_t(ts);
- //msg.target = QString::fromUtf8(targ);
msg.sender = QString::fromUtf8(s);
msg.text = QString::fromUtf8(m);
return in;
QT4_WRAP_CPP(_MOC ${core_MOCS})
ADD_LIBRARY(core ${core_SRCS} ${_MOC})
+TARGET_LINK_LIBRARIES(core common)
//SqliteStorage::init();
storage = new SqliteStorage();
connect(&server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
- //startListening(); // FIXME
+ startListening(); // FIXME make configurable
guiUser = 0;
- /*
- if(Global::runMode == Global::Monolithic) { // TODO Make GUI user configurable
- try {
- guiUser = storage->validateUser("Default", "password");
- } catch(Storage::AuthError) {
- guiUser = storage->addUser("Default", "password");
- }
- Q_ASSERT(guiUser);
- Global::setGuiUser(guiUser);
- createSession(guiUser);
- } else guiUser = 0;
- */
}
Core::~Core() {
void Core::processClientInit(QTcpSocket *socket, const QVariant &v) {
VarMap msg = v.toMap();
- if(msg["GUIProtocol"].toUInt() != GUI_PROTOCOL) {
+ if(msg["GuiProtocol"].toUInt() != GUI_PROTOCOL) {
//qWarning() << "Client version mismatch.";
throw Exception("GUI client version mismatch");
}
// Auth
UserId uid = storage->validateUser(msg["User"].toString(), msg["Password"].toString()); // throws exception if this failed
- VarMap reply = initSession(uid).toMap();
+ QVariant reply = initSession(uid);
validClients[socket] = uid;
QList<QVariant> sigdata;
- sigdata.append(CS_CORE_STATE); sigdata.append(QVariant(reply)); sigdata.append(QVariant()); sigdata.append(QVariant());
+ sigdata.append(CS_CORE_STATE); sigdata.append(reply); sigdata.append(QVariant()); sigdata.append(QVariant());
writeDataToDevice(socket, QVariant(sigdata));
}
//#include <QtCore>
#include <QStringList>
-//#include <QTcpSocket>
-//#include <QTcpServer>
+#include <QDebug>
/** This class is the Core side of the proxy. The Core connects its signals and slots to it,
* and the calls are marshalled and sent to (or received and unmarshalled from) the GuiProxy.
inline void csServerConnected(QString net) { send(CS_SERVER_CONNECTED, net); }
inline void csServerDisconnected(QString net) { send(CS_SERVER_DISCONNECTED, net); }
inline void csServerState(QString net, VarMap data) { send(CS_SERVER_STATE, net, data); }
- inline void csDisplayMsg(Message msg) { send(CS_DISPLAY_MSG, QVariant::fromValue(msg)); }
+ inline void csDisplayMsg(Message msg) { send(CS_DISPLAY_MSG, QVariant::fromValue(msg));}
inline void csDisplayStatusMsg(QString net, QString msg) { send(CS_DISPLAY_STATUS_MSG, net, msg); }
inline void csModeSet(QString net, QString target, QString mode) { send(CS_MODE_SET, net, target, mode); }
inline void csTopicSet(QString net, QString buf, QString topic) { send(CS_TOPIC_SET, net, buf, topic); }
buf = storage->getBufferId(user, s->getNetwork(), target);
}
Message msg(buf, type, text, sender, flags);
- msg.msgId = storage->logMessage(msg); //qDebug() << msg.msgId;
+ msg.msgId = storage->logMessage(msg);
Q_ASSERT(msg.msgId);
emit displayMsg(msg);
}
void serverDisconnected(QString net);
private:
+ UserId user;
+
CoreProxy *coreProxy;
Storage *storage;
QHash<QString, Server *> servers;
- UserId user;
VarMap sessionData;
QMutex mutex;
setAttribute(Qt::WA_DeleteOnClose);
coreState = 0;
+ /* We show ui.internalCore in any case, because we might want to run as monolithic client anyway at another time
if(Global::runMode == Global::Monolithic) {
connect(ui.internalCore, SIGNAL(toggled(bool)), ui.hostEdit, SLOT(setDisabled(bool)));
connect(ui.internalCore, SIGNAL(toggled(bool)), ui.port, SLOT(setDisabled(bool)));
ui.internalCore->setChecked(true);
} else {
- ui.internalCore->hide();
+ //ui.internalCore->hide();
}
+ */
connect(ui.newAccount, SIGNAL(clicked()), this, SLOT(createAccount()));
connect(ui.delAccount, SIGNAL(clicked()), this, SLOT(removeAccount()));
connect(ui.buttonBox1, SIGNAL(accepted()), this, SLOT(doConnect()));
ui.delAccount->setEnabled(en);
ui.internalCore->setEnabled(en);
ui.rememberPasswd->setEnabled(en);
- //ui.autoConnect->setEnabled(en);
- ui.autoConnect->setEnabled(false); // FIXME temporär
+ ui.autoConnect->setEnabled(en);
ui.buttonBox1->button(QDialogButtonBox::Ok)->setEnabled(en && checkInputValid());
}
bool CoreConnectDlg::willDoInternalAutoConnect() {
AccountSettings s;
+ if(Global::runMode != Global::Monolithic) return false;
if(ui.autoConnect->isChecked() && s.autoConnectAccount() == curacc && ui.internalCore->isChecked()) {
return true;
}
VarMap conninfo;
ui.stackedWidget->setCurrentIndex(1);
if(ui.internalCore->isChecked()) {
+ if(Global::runMode != Global::Monolithic) {
+ coreConnectionError(tr("Can't connect to internal core, since we are running as a standalone GUI!"));
+ return;
+ }
ui.connectionGroupBox->setTitle(tr("Connecting to internal core"));
ui.connectionProgress->hide();
} else {
ui.connectionGroupBox->setTitle(tr("Connecting to %1").arg(ui.hostEdit->text()));
conninfo["Host"] = ui.hostEdit->text();
- conninfo["Post"] = ui.port->value();
+ conninfo["Port"] = ui.port->value();
}
conninfo["User"] = ui.userEdit->text();
conninfo["Password"] = ui.passwdEdit->text();