278
// protocolMap maps pidgin account-names to kopete protocol names (as in Kopete::Contact::protocol()->pluginId())
279
QHash<QString, QString> protocolMap;
280
protocolMap.insert("msn", "WlmProtocol");
281
protocolMap.insert("icq", "ICQProtocol");
282
protocolMap.insert("aim", "AIMProtocol");
283
protocolMap.insert("jabber", "JabberProtocol");
284
protocolMap.insert("yahoo", "YahooProtocol");
285
protocolMap.insert("qq", "QQProtocol");
286
protocolMap.insert("irc", "IRCProtocol");
287
protocolMap.insert("gadu-gadu", "GaduProtocol");
288
protocolMap.insert("bonjour", "BonjourProtocol");
289
protocolMap.insert("meanwhile", "MeanwhileProtocol");
278
291
QString protocolFolder;
279
292
foreach (protocolFolder, logDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
280
293
logDir.cd(protocolFolder);
283
296
foreach (accountFolder, logDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
284
297
logDir.cd(accountFolder);
299
// check if we can map the protocol
300
if (!protocolMap.contains(protocolFolder)) {
301
detailsCursor.insertText(i18n("WARNING: There is no equivalent for protocol %1 in kopete.\n", protocolFolder));
305
const QString & protocol = protocolMap.value(protocolFolder);
286
307
// TODO use findContact?
287
308
Kopete::ContactList * cList = Kopete::ContactList::self();
288
309
QList<Kopete::Contact *> meList = cList->myself()->contacts();
289
310
Kopete::Contact *me;
290
311
bool found = false;
291
312
foreach (me, meList) {
292
if (me->protocol()->pluginId().contains(protocolFolder, Qt::CaseInsensitive) &&
293
me->account()->accountId().contains(accountFolder, Qt::CaseInsensitive)) {
313
if (me->protocol()->pluginId() == protocol && me->account()->accountId().contains(accountFolder, Qt::CaseInsensitive)) {
363
bool HistoryImport::isNickIncoming(const QString &nick, struct Log *log)
367
if (nick == log->me->nickName())
369
else if (nick == log->other->nickName())
371
else if (knownNicks.contains(nick))
372
incoming = knownNicks.value(nick);
374
int r = QMessageBox::question(NULL,
375
i18n("Cannot Map Nickname to Account"),
376
i18n("Did you use \"%1\" as nickname in history?", nick),
377
QMessageBox::Yes | QMessageBox::No | QMessageBox::Abort);
379
if (r == QMessageBox::Yes) {
380
knownNicks.insert(nick, true);
383
else if (r == QMessageBox::No) {
384
knownNicks.insert(nick, false);
395
383
QDateTime HistoryImport::extractTime(const QString &string, QDate ref)
397
385
QDateTime dateTime;
429
417
void HistoryImport::parsePidginTxt(QFile &file, struct Log *log, QDate date)
434
QString messageText, nick;
435
bool incoming = false; // =false to make the compiler not complain
437
while (!file.atEnd()) {
438
line = file.readLine();
421
struct Message message;
423
// this is to collect unknown nicknames (the list stores the index in log->messages of the messages that used the nickname)
424
// the bool says if that nickname is incoming (only used when the list is empty)
425
typedef QHash<QString, QPair<bool, QList<int> > > NickNameHash;
426
NickNameHash nicknames;
428
QTextStream str(&file);
429
// utf-8 seems to be default for pidgins-txt logs
430
str.setCodec("UTF-8");
432
while (!str.atEnd()) {
433
line = str.readLine();
440
435
if (line[0] == '(') {
441
if (!messageText.isEmpty()) {
442
// messageText contains an unwished newline at the end
443
if (messageText.endsWith('\n'))
444
messageText.remove(-1, 1);
445
struct Message message;
446
message.incoming = incoming;
447
message.text = messageText;
448
message.timestamp = dateTime;
436
if (!message.text.isEmpty()) {
437
/*// message.text contains an unwished newline at the end
438
if (message.text.endsWith('\n'))
439
message.text.chop(1); */
449
440
log->messages.append(message);
441
message.text.clear();
453
444
int endTime = line.indexOf(')')+1;
454
dateTime = extractTime(line.left(endTime), date);
445
message.timestamp = extractTime(line.left(endTime), date);
456
447
int nickEnd = QRegExp("\\s").indexIn(line, endTime + 1);
457
448
// TODO what if a nickname consists of two words? is this possible?
464
455
nick = line.mid(endTime+1, nickEnd - endTime - 2); // -2 to delete the colon
466
incoming = isNickIncoming(nick, log);
457
// detect if the message is in- or outbound
458
if (nick == log->me->displayName())
459
message.incoming = false;
460
else if (nick == log->other->displayName())
461
message.incoming = true;
462
else if (knownNicks.contains(nick))
463
message.incoming = knownNicks.value(nick);
465
// store this nick for later decision
466
nicknames[nick].second.append(log->messages.size());
468
nicknames[nick].first = message.incoming;
470
messageText = line.mid(nickEnd + 1);
473
message.text = line.mid(nickEnd + 1);
472
475
else if (line[0] == ' ') {
473
476
// an already started message is continued in this line
474
477
int start = QRegExp("\\S").indexIn(line);
475
messageText.append('\n' + line.mid(start));
478
message.text.append('\n' + line.mid(start));
478
if (!messageText.isEmpty()) {
479
struct Message message;
480
message.incoming = incoming;
481
message.text = messageText;
482
message.timestamp = dateTime;
481
if (!message.text.isEmpty())
483
482
log->messages.append(message);
484
// check if we can guess which nickname belongs to us
485
NickNameHash::iterator itr;
486
NickNameHash::const_iterator itr2;
487
for (itr = nicknames.begin(); itr != nicknames.end(); ++itr) {
488
if (itr->second.isEmpty()) // no work for this one
490
bool haveAnother = false, lastIncoming = false;
491
// check against all other nicknames
492
for (itr2 = nicknames.constBegin(); itr2 != nicknames.constEnd(); ++itr2) {
493
if (itr2 == NickNameHash::const_iterator(itr)) // skip ourselve
496
// if there is another unknown nickname, we have no chance to guess which is our
497
if (!itr2->second.isEmpty())
500
lastIncoming = itr2->first;
503
// when there are more than one known nicknames, but with different incoming-values, we also can't guess which is ours
504
if (lastIncoming != itr2->first)
508
// we now can guess the incoming value of itr, namely !lastIncoming
509
if (haveAnother && itr2 == nicknames.constEnd()) {
512
detailsCursor.insertText(i18n("INFORMATION: Guessed %1 to be one of your nicks.\n", itr.key()));
514
detailsCursor.insertText(i18n("INFORMATION: Guessed %1 to be one of your buddys nicks.\n", itr.key()));
516
knownNicks.insert(itr.key(), !lastIncoming);
518
for (i = 0; i < itr->second.size(); i++)
519
log->messages[itr->second.at(i)].incoming = !lastIncoming;
520
itr->second.clear(); // we are finished with theese indexes
524
// iterate once again over the nicknames to detect which nicks are still not known. simply ask the user!
525
for (itr = nicknames.begin(); itr != nicknames.end(); ++itr) {
526
if (itr->second.isEmpty()) // no word for this one
530
int r = QMessageBox::question(NULL,
531
i18n("Cannot map Nickname to Account"),
532
i18n("Did you ever use \"%1\" as nickname in your history?", itr.key()),
533
QMessageBox::Yes | QMessageBox::No | QMessageBox::Abort);
535
if (r == QMessageBox::Yes) {
536
knownNicks.insert(itr.key(), false);
539
else if (r == QMessageBox::No) {
540
knownNicks.insert(itr.key(), true);
548
// set the queried incoming value to our already stored Messages
550
for (i = 0; i < itr->second.size(); i++)
551
log->messages[itr->second.at(i)].incoming = incoming;