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 ***************************************************************************/
16 #include <kio/slaveconfig.h>
17 #include <kio/netaccess.h>
18 #include <kio/jobclasses.h>
22 #include <qapplication.h>
26 Account* Account::instance = 0;
28 Account* Account::getInstance()
30 if ( instance == 0 ) {
31 instance = new Account();
43 bool Account::login( const QString& userID, const QString& password )
45 return getInstance()->loginInternal( userID, password );
48 bool Account::loginInternal( const QString& userID, const QString& password )
52 KURL url( "https://2chv.tora3.net/futen.cgi" );
53 QString postData = QString("ID=") + userID + QString("&PW=") + password;
55 KIO::SlaveConfig::self() ->setConfigData( "https",
59 m_job = KIO::http_post( url, postData.utf8(), false );
61 connect( m_job, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
62 SLOT( slotReceiveData( KIO::Job*, const QByteArray& ) ) );
63 connect( m_job, SIGNAL( result( KIO::Job* ) ), SLOT( slotResult( KIO::Job* ) ) );
64 m_job->addMetaData( "customHTTPHeader",
65 QString( "X-2ch-UA: Kita/%1" ).arg( VERSION ) );
66 m_job->addMetaData( "content-type",
67 "Content-Type: application/x-www-form-urlencoded" );
74 void Account::slotReceiveData( KIO::Job*, const QByteArray& data )
76 QCString str( data, data.size() );
80 void Account::slotResult( KIO::Job* job )
85 job->showErrorDialog();
88 QString str( m_data );
89 QRegExp regexp( "SESSION-ID=(.*)" );
90 if ( regexp.search( str ) == -1 )
92 m_sessionID = QString::null;
97 QString value = regexp.cap( 1 );
99 QRegExp error( "^ERROR:p+$" );
100 if ( error.search( value ) == -1 )
108 m_sessionID = QString::null;
114 // from netaccess.cpp
115 void qt_enter_modal( QWidget* widget );
116 void qt_leave_modal( QWidget* widget );
118 void Account::enter_loop()
120 QWidget dummy( 0, 0, WType_Dialog | WShowModal );
121 dummy.setFocusPolicy( QWidget::NoFocus );
122 qt_enter_modal( &dummy );
124 qt_leave_modal( &dummy );
127 #include "account.moc"