/* historylogger.cpp Copyright (c) 2008 by Timo Schluessler Kopete (c) 2008 by the Kopete developers ************************************************************************* * * * 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. * * * ************************************************************************* */ #ifndef HISTORYIMPORT_H #define HISTORYIMPORT_H #include #include #include "kopeteglobal.h" #include "kopetecontact.h" #include "kopetemessage.h" /** * @author Timo Schluessler */ class HistoryImport : public KDialog { Q_OBJECT public: HistoryImport(QWidget *parent); ~HistoryImport(); private: /** * Used for internal storage of a message. */ struct Message { bool incoming; QString text; QDateTime timestamp; }; /** * Holds the messages sent and received between two specified contacts. */ struct Log { Kopete::Contact *me; Kopete::Contact *other; QList messages; /** * Comparison between the Message lists is not neccessary because we need this operator * only in displayLog() to get the index of this log in logs. */ bool operator==(const struct Log & cmp) { if (cmp.me == me && cmp.other == other/* && other.messages == messages*/) return true; else return false; } }; /** * Parses @param file and appends the found messages to @param log. */ void parsePidginXml(QFile & file, struct Log *log, QDate date); /** * Parses @param file and appends the found messages to @param log. */ void parsePidginTxt(QFile & file, struct Log *log, QDate date); /** * Inserts @param log into treeView and prepares to display it when clicking on it. */ void displayLog(struct Log *log); /** * Looks up if an item with @param text exists already as child of @param parent. * If not, it creates one. */ QStandardItem * findItem(QString text, QStandardItem *parent); /** * @return the number of files found in @param depth th subdir of @param dir. */ int countLogs(QDir dir, int depth); /** * Checks if nickname @param nick can be mapped to either @param log ->me or @param log ->other. * If not it asks the user if it is his nickname or someone elses. */ bool isNickIncoming(QString nick, struct Log *log); /** * Trys to extract the time from @param string using formats specified in timeFormats. * @param ref is used when @param string doesn't contain a date or to adjust a found date. * @param ref is taken from the filename of the log. */ QDateTime extractTime(QString string, QDate ref); QStringList timeFormats; QTreeView *treeView; QTextEdit *display; /** * Used for adding details to the details widget. */ QTextCursor detailsCursor; /** * Enables/disables auto search for log dirs. */ QCheckBox *selectByHand; /** * Contains all already parsed logs. */ QList logs; /** * Used for mapping nickname to account. See isNickIncoming(). */ QHash knownNicks; int amount; bool cancel; private slots: /** * Starts parsing history from pidgin. * Default path is ~/.purple/logs. */ void importPidgin(void); void save(void); void itemClicked(const QModelIndex & index); }; #endif