1 /***************************************************************************
2 * Copyright (C) 2004 by Kita Developers *
3 * ikemo@users.sourceforge.jp *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
12 #include <QtCore/QByteArray>
13 #include <QtCore/QRegExp>
17 #include <kio/jobuidelegate.h>
18 #include <kio/slaveconfig.h>
24 Account* Account::instance = 0;
26 Account* Account::getInstance()
29 instance = new Account();
41 bool Account::login(const QString& userID, const QString& password)
43 return getInstance() ->loginInternal(userID, password);
46 bool Account::loginInternal(const QString& userID, const QString& password)
50 KUrl url("https://2chv.tora3.net/futen.cgi");
51 QString postData = QString("ID=") + userID + QString("&PW=") + password;
53 KIO::SlaveConfig::self() ->setConfigData("https",
57 m_job = KIO::http_post(url, postData.toUtf8(), false);
59 connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
60 SLOT(slotReceiveData(KIO::Job*, const QByteArray&)));
61 connect(m_job, SIGNAL(result(KIO::Job*)), SLOT(slotResult(KIO::Job*)));
62 m_job->addMetaData("customHTTPHeader",
63 QString("X-2ch-UA: Kita/%1").arg(VERSION));
64 m_job->addMetaData("content-type",
65 "Content-Type: application/x-www-form-urlencoded");
67 QEventLoop m_eventLoop;
73 void Account::slotReceiveData(KIO::Job*, const QByteArray& data)
78 void Account::slotResult(KIO::Job* job)
82 job->ui()->setWindow(0);
83 job->ui()->showErrorMessage();
87 QRegExp regexp("SESSION-ID=(.*)");
88 if (regexp.indexIn(str) == -1) {
92 QString value = regexp.cap(1);
94 QRegExp error("^ERROR:p+$");
95 if (error.indexIn(value) == -1) {