From: <wr...@us...> - 2004-08-30 12:19:37
|
Update of /cvsroot/sim-icq/sim/plugins/_core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16528/plugins/_core Modified Files: core.cpp historywnd.cpp history.cpp history.h Log Message: Add history exporting Index: core.cpp =================================================================== RCS file: /cvsroot/sim-icq/sim/plugins/_core/core.cpp,v retrieving revision 1.102 retrieving revision 1.103 diff -C2 -d -r1.102 -r1.103 *** core.cpp 7 Jul 2004 09:10:22 -0000 1.102 --- core.cpp 30 Aug 2004 12:19:16 -0000 1.103 *************** *** 817,820 **** --- 817,827 ---- eCmd.process(); + cmd->id = CmdHistorySave; + cmd->text = I18N_NOOP("&Save as text"); + cmd->icon = "filesave"; + cmd->accel = "Ctrl+S"; + cmd->bar_grp = 0x6000; + eCmd.process(); + cmd->id = CmdBgColor; cmd->text = I18N_NOOP("Back&ground color"); Index: historywnd.cpp =================================================================== RCS file: /cvsroot/sim-icq/sim/plugins/_core/historywnd.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** historywnd.cpp 23 Apr 2004 10:08:06 -0000 1.8 --- historywnd.cpp 30 Aug 2004 12:19:27 -0000 1.9 *************** *** 30,33 **** --- 30,41 ---- #include <qlayout.h> #include <qstringlist.h> + #include <qmessagebox.h> + + #ifdef USE_KDE + #include <kfiledialog.h> + #define QFileDialog KFileDialog + #else + #include <qfiledialog.h> + #endif #include <time.h> *************** *** 176,179 **** --- 184,216 ---- return e->param(); } + if (cmd->id == CmdHistorySave){ + string s = QFileDialog::getSaveFileName(QString::null, QString::null, this); + if (s.length()){ + bool res = true; + if (QFile::exists(s)){ + QMessageBox mb(i18n("Error"), i18n("File already exists. Overwrite?"), + QMessageBox::Warning, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No, + QMessageBox::Cancel | QMessageBox::Escape); + mb.setButtonText(QMessageBox::Yes, i18n("&Overwrite")); + mb.setButtonText(QMessageBox::No, i18n("&Append")); + switch (mb.exec()){ + case QMessageBox::Yes: + res = History::save(m_id, s.c_str(), false); + break; + case QMessageBox::No: + res = History::save(m_id, s.c_str(), true); + break; + case QMessageBox::Cancel: + break; + } + }else + res = History::save(m_id, s.c_str()); + if (!res) + QMessageBox::critical(this, i18n("Error"), i18n("Save failed"), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); + } + return e->param(); + } if (cmd->id == CmdHistoryFind){ m_filter = ""; Index: history.cpp =================================================================== RCS file: /cvsroot/sim-icq/sim/plugins/_core/history.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** history.cpp 16 Apr 2004 00:52:07 -0000 1.16 --- history.cpp 30 Aug 2004 12:19:27 -0000 1.17 *************** *** 832,834 **** } ! --- 832,874 ---- } ! bool History::save(unsigned id, const char *file_name, bool bAppend) ! { ! QFile f(file_name); ! int mode = IO_WriteOnly | IO_Translate; ! if (bAppend) ! mode |= IO_Append; ! if (f.open(mode)){ ! QTextStream stream(&f); ! HistoryIterator it(id); ! it.begin(); ! const QString owner = getContacts()->owner()->getName(), ! contact = getContacts()->contact(id)->getName(); ! for (;;) { ! Message *msg = ++it; ! if ((msg == NULL)) ! break; ! time_t t = msg->getTime(); ! char* time = new char[9]; ! strftime(time, 9, "%H:%M:%S", localtime(&t)); ! stream << (msg->getFlags() & MESSAGE_RECEIVED ? contact : owner) ! << " (" << formatDate(t) << " " << time << "):\n" ! << msg->getPlainText() ! << "\n\n"; ! } ! const int status = f.status(); ! #if COMPAT_QT_VERSION >= 0x030200 ! const QString errorMessage = f.errorString(); ! #else ! const QString errorMessage = "write failed"; ! #endif ! f.close(); ! if (status != IO_Ok) { ! log(L_ERROR, "I/O error during write to file %s : %s", file_name, (const char*)errorMessage.local8Bit()); ! return false; ! } ! return true; ! }else{ ! log(L_ERROR, "Can't open %s for writing", file_name); ! return false; ! } ! } Index: history.h =================================================================== RCS file: /cvsroot/sim-icq/sim/plugins/_core/history.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** history.h 6 Jan 2004 01:51:44 -0000 1.6 --- history.h 30 Aug 2004 12:19:27 -0000 1.7 *************** *** 48,51 **** --- 48,52 ---- static void del(unsigned msg_id); static void remove(Contact *contact); + static bool save(unsigned id, const char *file_name, bool bAppend = false); static Message *load(unsigned id, const char *client, unsigned contact); protected: |