Import release 2.0alpha2
This commit is contained in:
+221
-76
@@ -17,46 +17,37 @@
|
||||
|
||||
#include "initialview.h"
|
||||
|
||||
#include "utils/kmessconfig.h"
|
||||
#include "accountsmanager.h"
|
||||
#include "account.h"
|
||||
#include "kmessdebug.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDateTime>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPixmap>
|
||||
#include <QTimer>
|
||||
#include <QToolButton>
|
||||
|
||||
#include <KApplication>
|
||||
#include <KComboBox>
|
||||
#include <KConfig>
|
||||
#include <KGlobal>
|
||||
#include <KGlobalSettings>
|
||||
#include <kdeversion.h>
|
||||
#include <KIconLoader>
|
||||
#include <KLineEdit>
|
||||
#include <KLocale>
|
||||
#include <KStandardDirs>
|
||||
|
||||
|
||||
|
||||
// The constructor
|
||||
InitialView::InitialView( QWidget *parent, const QList<Account*>accountList )
|
||||
InitialView::InitialView( QWidget *parent )
|
||||
: QWidget( parent )
|
||||
, Ui::InitialView()
|
||||
, isConnecting_( false )
|
||||
{
|
||||
// Set up the UI first
|
||||
setupUi( this );
|
||||
|
||||
// Set the username box with the last used email address
|
||||
config_ = KGlobal::config()->group( "InitialView" );
|
||||
config_ = KMessConfig::instance()->getGlobalConfig( "InitialView" );
|
||||
defaultHandle_ = config_.readEntry( "defaultHandle", "me@hotmail.com" );
|
||||
|
||||
// Enable auto completion
|
||||
handleCombobox_->setCompletionMode( KGlobalSettings::CompletionPopup );
|
||||
|
||||
// Select an image to load into the main screen.. mmmm, eggs!
|
||||
// Applied both in InitialView and AutologinView.
|
||||
QString imageName;
|
||||
QDate currentDate = QDate::currentDate();
|
||||
if( currentDate.month() == 12 && currentDate.day() > 15 )
|
||||
@@ -67,15 +58,12 @@ InitialView::InitialView( QWidget *parent, const QList<Account*>accountList )
|
||||
{
|
||||
imageName = "kmesslogo";
|
||||
}
|
||||
|
||||
// Load the chosen icon
|
||||
KIconLoader *loader = KIconLoader::global();
|
||||
QPixmap icon = loader->loadIcon( imageName, KIconLoader::User );
|
||||
loader_ = KIconLoader::global();
|
||||
QPixmap icon = loader_->loadIcon( imageName, KIconLoader::User );
|
||||
kmessLogo_->setPixmap( icon );
|
||||
kmessLogo_->setMinimumSize( icon.width(), icon.height() );
|
||||
|
||||
connectButton_->setIcon( loader->loadIcon( "network-connect", KIconLoader::Small, KIconLoader::SizeMedium ) );
|
||||
|
||||
// Add the items to the initial status combo box
|
||||
QStringList states;
|
||||
states << i18n("Online")
|
||||
@@ -88,7 +76,8 @@ InitialView::InitialView( QWidget *parent, const QList<Account*>accountList )
|
||||
initialStatus_->insertItems( 0, states );
|
||||
|
||||
// Load the accounts list into our combo box
|
||||
foreach( Account *account, accountList )
|
||||
const QList<Account*> accountsList = AccountsManager::instance()->getAccounts();
|
||||
foreach( Account *account, accountsList )
|
||||
{
|
||||
addAccount( account );
|
||||
}
|
||||
@@ -99,15 +88,39 @@ InitialView::InitialView( QWidget *parent, const QList<Account*>accountList )
|
||||
// Connect the remaining signals
|
||||
connect( handleCombobox_, SIGNAL( editTextChanged(const QString&) ),
|
||||
this, SLOT ( updateView() ) );
|
||||
// TODO: Remove this workaround before the KMess2 release. KDE4.1 will have a fix.
|
||||
#if KDE_IS_VERSION(4,0,70)
|
||||
connect( handleCombobox_, SIGNAL( returnPressed() ),
|
||||
connectButton_, SLOT ( animateClick() ) );
|
||||
#else
|
||||
connect( handleCombobox_->lineEdit(), SIGNAL( returnPressed() ),
|
||||
connectButton_, SLOT ( animateClick() ) );
|
||||
#endif
|
||||
connect( connectButton_, SIGNAL( clicked() ),
|
||||
this, SLOT ( connectToMsnDelayed() ) );
|
||||
this, SLOT ( slotConnectClicked() ) );
|
||||
connect( rememberAccountCheckBox_, SIGNAL( stateChanged(int) ),
|
||||
this, SLOT ( rememberAccountStateChanged(int) ) );
|
||||
connect( optionsLabel_, SIGNAL( leftClickedUrl(QString) ),
|
||||
this, SLOT ( toggleOptionsBox() ) );
|
||||
|
||||
// When an account is edited, reflect the changes in the accounts list
|
||||
connect( AccountsManager::instance(), SIGNAL( accountChanged(Account*,QString,QString) ),
|
||||
this, SLOT ( updateView() ) );
|
||||
|
||||
// When (if!) the passwords have been read from the user's password wallet, show them
|
||||
connect( AccountsManager::instance(), SIGNAL( passwordsReady() ),
|
||||
this, SLOT ( updateView() ) );
|
||||
|
||||
// The status is needed only later
|
||||
statusLabel_->hide();
|
||||
|
||||
// Force an update of the view
|
||||
setEnabled( true );
|
||||
updateView();
|
||||
|
||||
// Use Solid to find out whether we're connected or not, and apply the status immediately
|
||||
connect( Solid::Networking::notifier(), SIGNAL( statusChanged(Solid::Networking::Status) ),
|
||||
this, SLOT ( slotConnectionStatusChanged(Solid::Networking::Status) ) );
|
||||
slotConnectionStatusChanged( Solid::Networking::status() );
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +144,7 @@ void InitialView::addAccount(Account *account)
|
||||
accounts_.insert( handle, account );
|
||||
|
||||
// Add an entry for the account to the dropdown list
|
||||
handleCombobox_->addItem( handle ); // + " (" + account->getFriendlyName() + ")" );
|
||||
handleCombobox_->addItem( handle );
|
||||
handleCombobox_->completionObject()->addItem( handle );
|
||||
|
||||
// Select the account in the combobox if it's the default account.
|
||||
@@ -181,60 +194,37 @@ void InitialView::changedAccount( QString oldName, QString newName )
|
||||
|
||||
|
||||
|
||||
// Connect to MSN with the entered account data
|
||||
void InitialView::connectToMsn()
|
||||
{
|
||||
QString handle = getSelectedHandle();
|
||||
|
||||
// Avoid connecting with empty fields
|
||||
if( handle.isEmpty() || passwordEdit_->text().isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Also don't connect if the handle is invalid
|
||||
if( ! Account::isValidEmail( handle ) )
|
||||
{
|
||||
handleCombobox_->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the entered text
|
||||
config_.writeEntry( "defaultHandle", handle );
|
||||
|
||||
// Update the initial status
|
||||
Status initialStatus;
|
||||
|
||||
// Find out what status has been chosen
|
||||
switch( initialStatus_->currentIndex() )
|
||||
{
|
||||
case 1: initialStatus = STATUS_AWAY; break;
|
||||
case 2: initialStatus = STATUS_BE_RIGHT_BACK; break;
|
||||
case 3: initialStatus = STATUS_BUSY; break;
|
||||
case 4: initialStatus = STATUS_OUT_TO_LUNCH; break;
|
||||
case 5: initialStatus = STATUS_ON_THE_PHONE; break;
|
||||
case 6: initialStatus = STATUS_INVISIBLE; break;
|
||||
case 0:
|
||||
default: initialStatus = STATUS_ONLINE; break;
|
||||
}
|
||||
|
||||
// Inform parent with the account information
|
||||
emit connectWithAccount( handle, passwordEdit_->text(), rememberAccountCheckBox_->isChecked(),
|
||||
rememberPasswordCheckBox_->isChecked(), initialStatus );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The "connect" button was pressed, schedule connection
|
||||
* @brief Update the view when the network connection status changes
|
||||
*
|
||||
* This method avoids instant deletion of our widgets while they're still animating.
|
||||
* It happens because, when we emit the connectWithAccount signal, the receiver (the KMess class)
|
||||
* deletes this class, which widgets are still performing Qt4 microanimations.
|
||||
* This method receives KDE's Solid network connection status changes, and updates the view's widgets
|
||||
* to reflect it.
|
||||
*
|
||||
* @param newStatus The new status of the network connection
|
||||
*/
|
||||
void InitialView::connectToMsnDelayed()
|
||||
void InitialView::slotConnectionStatusChanged( Solid::Networking::Status newStatus )
|
||||
{
|
||||
QTimer::singleShot( 150, this, SLOT( connectToMsn() ) );
|
||||
// If Solid is unable to retrieve the status, assume we're connected
|
||||
bool isConnected = ( newStatus == Solid::Networking::Connected || newStatus == Solid::Networking::Unknown );
|
||||
|
||||
connectButton_->setEnabled( isConnected );
|
||||
|
||||
if( isConnected && ! isConnecting_ )
|
||||
{
|
||||
statusLabel_->setVisible( false );
|
||||
statusMessage( QString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( isConnecting_ )
|
||||
{
|
||||
// Force a disconnection
|
||||
connectButton_->click();
|
||||
}
|
||||
|
||||
statusLabel_->setVisible( true );
|
||||
statusMessage( i18n("Internet connection not available.") );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -301,6 +291,13 @@ void InitialView::updateView()
|
||||
passwordEdit_->setText( account->getPassword() );
|
||||
}
|
||||
|
||||
// Set the current account picture
|
||||
QPixmap picture( account->getPicturePath() );
|
||||
if( ! picture.isNull() )
|
||||
{
|
||||
pictureLabel_->setPixmap( picture );
|
||||
}
|
||||
|
||||
rememberAccountCheckBox_->setChecked( ! account->isGuestAccount() );
|
||||
rememberAccountCheckBox_->setDisabled( ! account->isGuestAccount() );
|
||||
|
||||
@@ -322,9 +319,23 @@ void InitialView::updateView()
|
||||
else
|
||||
{
|
||||
// User typed a new account name
|
||||
|
||||
// Set the default picture
|
||||
KStandardDirs *dirs = KGlobal::dirs();
|
||||
QPixmap picture( dirs->findResource( "data", "kmess/pics/kmesspic.png" ) );
|
||||
if( ! picture.isNull() )
|
||||
{
|
||||
pictureLabel_->setPixmap( picture );
|
||||
}
|
||||
|
||||
// Set the default options
|
||||
rememberAccountCheckBox_ ->setDisabled( false );
|
||||
rememberPasswordCheckBox_->setDisabled( false );
|
||||
rememberAccountCheckBox_ ->setChecked ( true );
|
||||
rememberPasswordCheckBox_->setChecked ( false );
|
||||
|
||||
// Clear password again
|
||||
passwordEdit_->setText( QString::null );
|
||||
rememberAccountCheckBox_->setDisabled( false );
|
||||
initialStatus_->setCurrentIndex( 0 );
|
||||
}
|
||||
|
||||
@@ -350,6 +361,140 @@ void InitialView::rememberAccountStateChanged( int state )
|
||||
|
||||
|
||||
|
||||
// Enable or disable the widgets when we're waiting or connecting
|
||||
void InitialView::setEnabled( bool isEnabled )
|
||||
{
|
||||
loginBox_ ->setEnabled( isEnabled );
|
||||
optionsBox_ ->setEnabled( isEnabled );
|
||||
optionsLabel_ ->setVisible( isEnabled );
|
||||
initialStatusLabel_->setEnabled( isEnabled );
|
||||
initialStatus_ ->setEnabled( isEnabled );
|
||||
statusLabel_ ->setVisible( ! isEnabled );
|
||||
|
||||
// Switch the button's look
|
||||
if( isEnabled )
|
||||
{
|
||||
connectButton_->setText( i18n( "Connect" ) );
|
||||
connectButton_->setIcon( loader_->loadIcon( "network-connect", KIconLoader::Small, KIconLoader::SizeMedium ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
connectButton_->setText( i18n( "Disconnect" ) );
|
||||
connectButton_->setIcon( loader_->loadIcon( "network-disconnect", KIconLoader::Small, KIconLoader::SizeMedium ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The connect/disconnect button has been clicked
|
||||
void InitialView::slotConnectClicked()
|
||||
{
|
||||
#ifdef KMESSDEBUG_INITIALVIEW
|
||||
kDebug() << "Connect button clicked," << (isConnecting_?"disconnecting":"connecting");
|
||||
#endif
|
||||
|
||||
// The button was acting as Disconnect button when it was clicked
|
||||
if( isConnecting_ )
|
||||
{
|
||||
isConnecting_ = false;
|
||||
|
||||
// Enable back the widgets to allow connecting again
|
||||
setEnabled( true );
|
||||
|
||||
emit disconnectClicked();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// The button was acting as Connect button when it was clicked
|
||||
|
||||
QString handle = getSelectedHandle();
|
||||
|
||||
// Avoid connecting with empty fields
|
||||
if( handle.isEmpty() || passwordEdit_->text().isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Also don't connect if the handle is invalid
|
||||
if( ! Account::isValidEmail( handle ) )
|
||||
{
|
||||
handleCombobox_->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the UI options for the selected handle
|
||||
handleCombobox_->setEditText( handle );
|
||||
|
||||
isConnecting_ = true;
|
||||
|
||||
// Disable the widgets to start connecting
|
||||
setEnabled( false );
|
||||
|
||||
// Save the currently selected account for the next logins
|
||||
defaultHandle_ = handle;
|
||||
config_.writeEntry( "defaultHandle", handle );
|
||||
|
||||
// Find out what status has been chosen
|
||||
Status initialStatus;
|
||||
switch( initialStatus_->currentIndex() )
|
||||
{
|
||||
case 1: initialStatus = STATUS_AWAY; break;
|
||||
case 2: initialStatus = STATUS_BE_RIGHT_BACK; break;
|
||||
case 3: initialStatus = STATUS_BUSY; break;
|
||||
case 4: initialStatus = STATUS_OUT_TO_LUNCH; break;
|
||||
case 5: initialStatus = STATUS_ON_THE_PHONE; break;
|
||||
case 6: initialStatus = STATUS_INVISIBLE; break;
|
||||
case 0:
|
||||
default: initialStatus = STATUS_ONLINE; break;
|
||||
}
|
||||
|
||||
// Inform parent with the account information
|
||||
emit connectWithAccount( handle, passwordEdit_->text(), rememberAccountCheckBox_->isChecked(),
|
||||
rememberPasswordCheckBox_->isChecked(), initialStatus );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Start connecting with a specified account
|
||||
void InitialView::startedConnecting( const QString handle )
|
||||
{
|
||||
// Do nothing if an invalid or no account has been selected
|
||||
if( handle.isEmpty() || ! accounts_.contains( handle ) )
|
||||
{
|
||||
#ifdef KMESSDEBUG_INITIALVIEW
|
||||
kDebug() << "Not updating view for invalid handle" << handle;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef KMESSDEBUG_INITIALVIEW
|
||||
kDebug() << "Updating UI for" << handle;
|
||||
#endif
|
||||
|
||||
// Set the UI options for the selected handle
|
||||
handleCombobox_->setEditText( handle );
|
||||
|
||||
isConnecting_ = true;
|
||||
|
||||
// Disable the widgets to start connecting
|
||||
setEnabled( false );
|
||||
|
||||
// Save the currently selected account for the next logins
|
||||
defaultHandle_ = handle;
|
||||
config_.writeEntry( "defaultHandle", handle );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change the connection status text
|
||||
void InitialView::statusMessage( QString text )
|
||||
{
|
||||
statusLabel_->setText( text );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Toggle displaying the Options box, which allows remembering accounts & passwords
|
||||
void InitialView::toggleOptionsBox()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user