Implement password changing from client.
[quassel.git] / src / client / client.cpp
index fe49f77..94a33d1 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   Copyright (C) 2005-2015 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -34,6 +34,7 @@
 #include "clientirclisthelper.h"
 #include "clientidentity.h"
 #include "clientignorelistmanager.h"
+#include "clienttransfermanager.h"
 #include "clientuserinputhandler.h"
 #include "coreaccountmodel.h"
 #include "coreconnection.h"
@@ -47,6 +48,7 @@
 #include "quassel.h"
 #include "signalproxy.h"
 #include "util.h"
+#include "clientauthhandler.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -102,10 +104,11 @@ Client::Client(QObject *parent)
     _inputHandler(0),
     _networkConfig(0),
     _ignoreListManager(0),
+    _transferManager(0),
     _messageModel(0),
     _messageProcessor(0),
     _coreAccountModel(new CoreAccountModel(this)),
-    _coreConnection(new CoreConnection(_coreAccountModel, this)),
+    _coreConnection(new CoreConnection(this)),
     _connected(false),
     _debugLog(&_debugLogBuffer)
 {
@@ -150,6 +153,8 @@ void Client::init()
     p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
     p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
 
+    p->attachSignal(this, SIGNAL(clientChangePassword(QString)));
+
     //connect(mainUi(), SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
     connect(mainUi(), SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore()));
     connect(this, SIGNAL(connected()), mainUi(), SLOT(connectedToCore()));
@@ -404,6 +409,10 @@ void Client::setSyncedToCore()
     _ignoreListManager = new ClientIgnoreListManager(this);
     signalProxy()->synchronize(ignoreListManager());
 
+    Q_ASSERT(!_transferManager);
+    _transferManager = new ClientTransferManager(this);
+    signalProxy()->synchronize(transferManager());
+
     // trigger backlog request once all active bufferviews are initialized
     connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
 
@@ -473,6 +482,12 @@ void Client::setDisconnectedFromCore()
         _ignoreListManager->deleteLater();
         _ignoreListManager = 0;
     }
+
+    if (_transferManager) {
+        _transferManager->deleteLater();
+        _transferManager = 0;
+    }
+
     // we probably don't want to save pending input for reconnect
     _userInputBuffer.clear();
 
@@ -633,7 +648,15 @@ void Client::markBufferAsRead(BufferId id)
         bufferSyncer()->requestMarkBufferAsRead(id);
 }
 
+void Client::changePassword(QString newPassword) {
+    CoreAccount account = currentCoreAccount();
+    account.setPassword(newPassword);
+    coreAccountModel()->createOrUpdateAccount(account);
+    emit clientChangePassword(newPassword);
+}
+
 
+#if QT_VERSION < 0x050000
 void Client::logMessage(QtMsgType type, const char *msg)
 {
     fprintf(stderr, "%s\n", msg);
@@ -653,3 +676,26 @@ void Client::logMessage(QtMsgType type, const char *msg)
         emit instance()->logUpdated(msgString);
     }
 }
+#else
+void Client::logMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
+{
+    Q_UNUSED(context);
+
+    fprintf(stderr, "%s\n", msg.toLocal8Bit().constData());
+    fflush(stderr);
+    if (type == QtFatalMsg) {
+        Quassel::logFatalMessage(msg.toLocal8Bit().constData());
+    }
+    else {
+        QString msgString = QString("%1\n").arg(msg);
+
+        //Check to see if there is an instance around, else we risk recursions
+        //when calling instance() and creating new ones.
+        if (!instanceExists())
+            return;
+
+        instance()->_debugLog << msgString;
+        emit instance()->logUpdated(msgString);
+    }
+}
+#endif