Commit 9a6d9a39 authored by Rafał Malinowski's avatar Rafał Malinowski

history_migration: #2503 fixed: crashes during history import from Kadu 0.6.5

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent c084a705
......@@ -27,6 +27,7 @@
* chat: fixed a bug in Adium chat styles engine causing messages to be often doubled when opening a chat widget (beevvy)
* history: #2480 probably fixed: crash when loading last day/week/month history into chat widget on 32bit systems (Vogel)
* history: various security improvements pointed by Mateusz Goik from http://www.aliantsoft.pl (Vogel)
* history_migration: #2503 fixed: crashes during history import from Kadu 0.6.5 (Vogel)
+++ version 0.11.0
* gui: #2454 fixed: memory leak in emoticons selector (Juzef)
......
......@@ -39,7 +39,7 @@
#include "history-migration-helper.h"
HistoryImportThread::HistoryImportThread(Account gaduAccount, const QString &path, const QList<UinsList> &uinsLists, int totalEntries, QObject *parent) :
QThread(parent), GaduAccount(gaduAccount), Path(path), UinsLists(uinsLists),
QObject(parent), GaduAccount(gaduAccount), Path(path), UinsLists(uinsLists),
TotalEntries(totalEntries), ImportedEntries(0), ImportedChats(0), TotalMessages(0),
ImportedMessages(0), Canceled(false), CancelForced(false)
{
......@@ -49,6 +49,12 @@ HistoryImportThread::~HistoryImportThread()
{
}
void HistoryImportThread::prepareChats()
{
foreach (const UinsList &uinsList, UinsLists)
chatFromUinsList(uinsList);
}
void HistoryImportThread::run()
{
// we have to use this guard as a parent for HistoryImporterChatData
......@@ -108,6 +114,8 @@ void HistoryImportThread::run()
}
History::instance()->setSyncEnabled(true);
emit finished();
}
void HistoryImportThread::cancel(bool force)
......
......@@ -23,7 +23,7 @@
#define HISTORY_IMPORT_THREAD_H
#include <QtCore/QList>
#include <QtCore/QThread>
#include <QtCore/QObject>
#include "accounts/account.h"
......@@ -32,7 +32,7 @@
class Chat;
struct HistoryEntry;
class HistoryImportThread : public QThread
class HistoryImportThread : public QObject
{
Q_OBJECT
......@@ -56,7 +56,7 @@ public:
HistoryImportThread(Account gaduAccount, const QString &path, const QList<UinsList> &uinsLists, int totalEntries, QObject *parent = 0);
virtual ~HistoryImportThread();
virtual void run();
void prepareChats();
int importedEntries() { return ImportedEntries; }
int importedChats() { return ImportedChats; }
......@@ -66,8 +66,12 @@ public:
bool wasCanceled() { return Canceled; }
public slots:
void run();
void cancel(bool force = false);
signals:
void finished();
};
#endif // HISTORY_IMPORT_THREAD_H
......@@ -23,6 +23,7 @@
#include <QtCore/QFile>
#include <QtCore/QList>
#include <QtCore/QThread>
#include <QtCore/QTimer>
#include <QtGui/QProgressDialog>
......@@ -56,7 +57,7 @@ HistoryImporter::~HistoryImporter()
if (Thread)
{
disconnect(Thread, SIGNAL(finished()), this, SLOT(threadFinished()));
Thread->cancel(true);
ImportThread->cancel(true);
Thread->wait(2000);
if (Thread->isRunning())
{
......@@ -94,8 +95,14 @@ void HistoryImporter::run()
return;
}
Thread = new HistoryImportThread(DestinationAccount, SourceDirectory, uinsLists, totalEntries, this);
connect(Thread, SIGNAL(finished()), this, SLOT(threadFinished()));
ImportThread = new HistoryImportThread(DestinationAccount, SourceDirectory, uinsLists, totalEntries);
ImportThread->prepareChats();
Thread = new QThread();
ImportThread->moveToThread(Thread);
connect(Thread, SIGNAL(started()), ImportThread, SLOT(run()));
connect(ImportThread, SIGNAL(finished()), this, SLOT(threadFinished()));
ProgressWindow = new HistoryImportWindow();
ProgressWindow->setChatsCount(uinsLists.size());
......@@ -113,17 +120,17 @@ void HistoryImporter::run()
void HistoryImporter::updateProgressWindow()
{
if (ProgressWindow && Thread)
if (ProgressWindow && ImportThread)
{
ProgressWindow->setChatsProgress(Thread->importedChats());
ProgressWindow->setMessagesCount(Thread->totalMessages());
ProgressWindow->setMessagesProgress(Thread->importedMessages());
ProgressWindow->setChatsProgress(ImportThread->importedChats());
ProgressWindow->setMessagesCount(ImportThread->totalMessages());
ProgressWindow->setMessagesProgress(ImportThread->importedMessages());
}
}
void HistoryImporter::threadFinished()
{
if (Thread && !Thread->wasCanceled() && SourceDirectory == KaduPaths::instance()->profilePath() + QLatin1String("history/"))
if (ImportThread && !ImportThread->wasCanceled() && SourceDirectory == KaduPaths::instance()->profilePath() + QLatin1String("history/"))
{
config_file.writeEntry("History", "Imported_from_0.6.5", true);
// this is no longer useful
......
......@@ -39,7 +39,8 @@ class HISTORY_MIGRATION_API HistoryImporter : public QObject
Account DestinationAccount;
QString SourceDirectory;
HistoryImportThread *Thread;
QThread *Thread;
HistoryImportThread *ImportThread;
HistoryImportWindow *ProgressWindow;
private slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment