Import release 2.0beta1

This commit is contained in:
Mario Fetka
2009-03-23 23:26:37 +00:00
parent 8b3dac7ce6
commit a899084e37
373 changed files with 147541 additions and 68476 deletions
+440 -103
View File
@@ -17,32 +17,48 @@
#include "initialview.h"
#include "network/msnconnection.h" // Required for the offline socket #define
#include "utils/kmessconfig.h"
#include "utils/kmessshared.h"
#include "accountsmanager.h"
#include "account.h"
#include "kmessdebug.h"
#include <QTimer>
#include <QWheelEvent>
#include <kdeversion.h>
#include <KIconEffect>
#include <KIconLoader>
#include <KLocale>
#include <KStandardDirs>
/**
* Reconnection timeout
*
* This number is the time, expressed in seconds, after which a connection is attempted again
*/
#ifndef RECONNECTION_TIME
#define RECONNECTION_TIME 30
#endif
// The constructor
InitialView::InitialView( QWidget *parent )
: QWidget( parent )
, Ui::InitialView()
, isConnecting_( false )
, isConnectingUI_( false )
, networkStatus_( Solid::Networking::Connected )
, reconnectionRemainingSeconds_( 30 )
, triedConnecting_( false )
{
// Set up the UI first
setupUi( this );
// Set the username box with the last used email address
config_ = KMessConfig::instance()->getGlobalConfig( "InitialView" );
defaultHandle_ = config_.readEntry( "defaultHandle", "me@hotmail.com" );
lastUsedHandle_ = config_.readEntry( "defaultHandle", "me@hotmail.com" );
// Enable auto completion
handleCombobox_->setCompletionMode( KGlobalSettings::CompletionPopup );
@@ -52,11 +68,11 @@ InitialView::InitialView( QWidget *parent )
QDate currentDate = QDate::currentDate();
if( currentDate.month() == 12 && currentDate.day() > 15 )
{
imageName = "kmesslogo2";
imageName = "kmessstrip2";
}
else
{
imageName = "kmesslogo";
imageName = "kmessstrip1";
}
// Load the chosen icon
loader_ = KIconLoader::global();
@@ -82,25 +98,23 @@ InitialView::InitialView( QWidget *parent )
addAccount( account );
}
// Initially hide the options box
optionsBox_->hide();
// Connect the remaining signals
connect( handleCombobox_, SIGNAL( editTextChanged(const QString&) ),
this, SLOT ( updateView() ) );
#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 ( slotConnectClicked() ) );
connect( rememberAccountCheckBox_, SIGNAL( stateChanged(int) ),
this, SLOT ( rememberAccountStateChanged(int) ) );
connect( optionsLabel_, SIGNAL( leftClickedUrl(QString) ),
this, SLOT ( toggleOptionsBox() ) );
connect( forgottenPasswordLabel_, SIGNAL( leftClickedUrl(const QString&) ),
this, SLOT ( slotClickedUrl(const QString&) ) );
connect( newAccountLabel_, SIGNAL( leftClickedUrl(const QString&) ),
this, SLOT ( slotClickedUrl(const QString&) ) );
connect( statusLabel_, SIGNAL( linkActivated(const QString&) ),
this, SLOT ( slotClickedUrl(const QString&) ) );
// Enable tooltips for the two URL labels (they're disabled by default)
newAccountLabel_->setUseTips( true );
forgottenPasswordLabel_->setUseTips( true );
// When an account is edited, reflect the changes in the accounts list
connect( AccountsManager::instance(), SIGNAL( accountChanged(Account*,QString,QString) ),
@@ -110,17 +124,24 @@ InitialView::InitialView( QWidget *parent )
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() );
// Set the initial status of the widgets
reset();
// Add an event filter to create a quick account chooser
pictureLabel_->installEventFilter( this );
installEventFilter( this );
// Set up the timers
reconnectionTimer_.setInterval( 1000 ); // Fire every second
connect( &reconnectionTimer_, SIGNAL( timeout() ),
this, SLOT ( slotReconnectTimerEvent() ) );
statusMessageTimer_.setSingleShot( true );
connect( &statusMessageTimer_, SIGNAL( timeout() ),
this, SLOT ( statusMessage() ) );
}
@@ -148,9 +169,9 @@ void InitialView::addAccount(Account *account)
handleCombobox_->completionObject()->addItem( handle );
// Select the account in the combobox if it's the default account.
if( handle == defaultHandle_ )
if( handle == lastUsedHandle_ )
{
handleCombobox_->setCurrentItem( defaultHandle_ );
handleCombobox_->setCurrentItem( lastUsedHandle_ );
updateView();
}
}
@@ -194,6 +215,98 @@ void InitialView::changedAccount( QString oldName, QString newName )
/**
* @brief Automatically reconnect with a specified account [slot].
*
* This method starts reconnecting to an account
*
* @param handle The email address of the account to reconnect
*/
void InitialView::reconnect( QString handle )
{
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Reconnecting account" << handle;
#endif
Account *account = accounts_[ handle ];
if( account == 0 )
{
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Account not found, aborting.";
#endif
statusMessage( i18nc( "Status message on login screen",
"Cannot reconnect: account not found." ),
10000 );
return;
}
// If the account has not a saved password, we can't reconnect
if( account->getPassword().isEmpty() || ! account->getSavePassword() )
{
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Account has no password, aborting.";
#endif
statusMessage( i18nc( "Status message on login screen",
"Cannot reconnect: this account has no saved password." ),
10000 );
return;
}
// Save the account which we will connect to, later on
reconnectionHandle_ = handle;
triedConnecting_ = true;
switch( networkStatus_ )
{
// We're connected to the network, try connecting now
case Solid::Networking::Connected:
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Network status: Connected. Waiting a little bit for reconnection.";
#endif
reconnectionRemainingSeconds_ = 5;
break;
// The network connection is down, wait for it to come up again
case Solid::Networking::Unconnected:
case Solid::Networking::Connecting:
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Network status: Unconnected/connecting. Waiting for a connection.";
#endif
setEnabled( false );
statusMessage( i18nc( "Status message on login screen",
"Waiting for an Internet connection to reconnect...<br /><a href='%1'>Reconnect now!</a>",
"kmess://reconnect/" ) );
return;
// The connection is being brought down, wait for it
case Solid::Networking::Disconnecting:
kDebug() << "Network status: disconnecting. Waiting a moment for reconnection.";
reconnectionRemainingSeconds_ = 30;
return;
// The network connection status is not known, wait a while before reconnecting
case Solid::Networking::Unknown:
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Network status: Unknown. Scheduling reconnection.";
#endif
reconnectionRemainingSeconds_ = 30;
break;
}
// Start the reconnection delay timer
setEnabled( false );
reconnectionTimer_.start();
slotReconnectTimerEvent();
}
/**
* @brief Update the view when the network connection status changes
*
@@ -204,36 +317,108 @@ void InitialView::changedAccount( QString oldName, QString newName )
*/
void InitialView::slotConnectionStatusChanged( Solid::Networking::Status newStatus )
{
// If Solid is unable to retrieve the status, assume we're connected
bool isConnected = ( newStatus == Solid::Networking::Connected || newStatus == Solid::Networking::Unknown );
#if KMESS_DEBUG == 1 && KMESS_ENABLE_NULL_SOCKET == 1
networkStatus_ = Solid::Networking::Connected;
#else
networkStatus_ = newStatus;
#endif
connectButton_->setEnabled( isConnected );
if( isConnected && ! isConnecting_ )
#ifdef KMESSDEBUG_INITIALVIEW
QString status;
switch( networkStatus_ )
{
statusLabel_->setVisible( false );
statusMessage( QString() );
case Solid::Networking::Unknown: status = "Unknown"; break;
case Solid::Networking::Unconnected: status = "Unconnected"; break;
case Solid::Networking::Disconnecting: status = "Disconnecting"; break;
case Solid::Networking::Connecting: status = "Connecting"; break;
case Solid::Networking::Connected: status = "Connected"; break;
default: status = "Other (not known)"; break;
}
kDebug() << "The network connection status has changed to:" << status << ".";
#endif
// If Solid is unable to retrieve the status, assume we're connected
if( networkStatus_ == Solid::Networking::Connected
|| networkStatus_ == Solid::Networking::Unknown )
{
if( ! triedConnecting_ )
{
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "no connection attempt active, do nothing.";
#endif
}
else
{
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "A connection attempt was in progress, continueing...";
#endif
if( ! reconnectionHandle_.isEmpty() )
{
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Reconnection asked, scheduling.";
#endif
reconnect( reconnectionHandle_ );
}
else
{
statusMessage();
setEnabled( true );
}
}
}
else
{
if( isConnecting_ )
// Solid connection is not up.
// Reset the dialog, keep the "isConnecting" status
setEnabled( ! triedConnecting_ );
if( triedConnecting_ )
{
// Force a disconnection
connectButton_->click();
// Still show the same message.
statusMessage( i18nc( "Status message on login screen",
"Waiting for an Internet connection to reconnect...<br /><a href='%1'>Reconnect now!</a>",
"kmess://reconnect/" ) );
}
else
{
statusMessage( i18nc( "Status message on login screen", "Internet connection not available." ) );
}
statusLabel_->setVisible( true );
statusMessage( i18n("Internet connection not available.") );
}
}
// Update the reconnection timer data
void InitialView::slotReconnectTimerEvent()
{
if( reconnectionRemainingSeconds_ == 0 )
{
// Halt the timer
reconnectionTimer_.stop();
// Try reconnecting now
startConnecting( reconnectionHandle_ );
return;
}
statusMessage( i18ncp( "Status message on login screen",
"Waiting %1 second before reconnection...<br /><a href='%2'>Reconnect now!</a>",
"Waiting %1 seconds before reconnection...<br /><a href='%2'>Reconnect now!</a>",
reconnectionRemainingSeconds_,
"kmess://reconnect/" ),
5000 );
// Reduce time for reconnect
--reconnectionRemainingSeconds_;
}
// The account was deleted
void InitialView::deleteAccount(Account *account)
{
// Remove account from hashmap.
QString handle = account->getHandle();
QString handle( account->getHandle() );
accounts_.remove(handle);
// Remove account from completionbox (extended qlistbox)
@@ -263,7 +448,7 @@ void InitialView::deleteAccount(Account *account)
QString InitialView::getSelectedHandle() const
{
// Get handle, remove appended friendlyname if present
QString handle = handleCombobox_->currentText();
QString handle( handleCombobox_->currentText() );
if( handle.contains(' ') )
{
handle = handle.section(' ', 0, 0);
@@ -280,7 +465,7 @@ void InitialView::updateView()
if( account != 0 )
{
// User typed the full account name without using autocompletion.
if( account->getPassword().isEmpty() || ! account->getSavePassword() )
if( ! account->getSavePassword() )
{
rememberPasswordCheckBox_->setChecked( false );
passwordEdit_->setText( QString() );
@@ -361,25 +546,44 @@ void InitialView::rememberAccountStateChanged( int state )
// Reset the view to its initial state
void InitialView::reset()
{
// Reset internal data
setEnabled( true );
reconnectionHandle_ = QString();
reconnectionTimer_.stop();
triedConnecting_ = false;
// Update the view again with regard to the current network status
updateView();
statusMessage();
slotConnectionStatusChanged( Solid::Networking::status() );
}
// 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 );
isConnectingUI_ = ( ! isEnabled );
initialStatusLabel_ ->setEnabled( isEnabled );
initialStatus_ ->setEnabled( isEnabled );
handleCombobox_ ->setEnabled( isEnabled );
passwordEdit_ ->setEnabled( isEnabled );
rememberAccountCheckBox_ ->setEnabled( isEnabled );
rememberPasswordCheckBox_->setEnabled( isEnabled );
// Switch the button's look
if( isEnabled )
{
connectButton_->setText( i18n( "Connect" ) );
connectButton_->setText( i18nc( "Button label", "&Connect" ) );
connectButton_->setIcon( loader_->loadIcon( "network-connect", KIconLoader::Small, KIconLoader::SizeMedium ) );
}
else
{
connectButton_->setText( i18n( "Disconnect" ) );
connectButton_->setText( i18nc( "Button label", "&Cancel" ) );
connectButton_->setIcon( loader_->loadIcon( "network-disconnect", KIconLoader::Small, KIconLoader::SizeMedium ) );
}
}
@@ -390,49 +594,82 @@ void InitialView::setEnabled( bool isEnabled )
void InitialView::slotConnectClicked()
{
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Connect button clicked," << (isConnecting_?"disconnecting":"connecting");
kDebug() << "Connect button clicked," << ( isConnectingUI_ ? "disconnecting" : "connecting" );
#endif
// The button was acting as Disconnect button when it was clicked
if( isConnecting_ )
if( isConnectingUI_ )
{
isConnecting_ = false;
emit disconnectClicked();
// Enable back the widgets to allow connecting again
setEnabled( true );
emit disconnectClicked();
reset();
return;
}
// The button was acting as Connect button when it was clicked
QString handle = getSelectedHandle();
startConnecting( getSelectedHandle() );
}
/** Start connecting with a specified account.
*
* It can also simply update the UI, without actually requesting a connection.
* KMess' autologin functions connect by themselves, so this is required.
*
* @param handle Handle of the account to connect with
* @param emitConnectionSignal Whether to emit the connection request signal
* to the KMess class or not
*/
bool InitialView::startConnecting( const QString handle, bool emitConnectionSignal )
{
// Fill the UI fields with the selected handle's details, if any
// Selecting the account this way also makes a saved account's
// password to appear
handleCombobox_->setEditText( handle );
// Avoid connecting with empty fields
if( handle.isEmpty() || passwordEdit_->text().isEmpty() )
{
return;
statusMessage( i18nc( "Status message on login screen",
"Please, fill both your email and password." ),
10000 );
// Select the box with the error
if( handle.isEmpty() )
{
handleCombobox_->setFocus();
}
else
{
passwordEdit_->setFocus();
}
return false;
}
// Also don't connect if the handle is invalid
if( ! Account::isValidEmail( handle ) )
{
statusMessage( i18nc( "Status message on login screen",
"Please, enter a valid email address." ),
10000 );
handleCombobox_->setFocus();
return;
return false;
}
// Set the UI options for the selected handle
handleCombobox_->setEditText( handle );
isConnecting_ = true;
#ifdef KMESSDEBUG_INITIALVIEW
kDebug() << "Connecting with handle:" << handle;
#endif
// Disable the widgets to start connecting
setEnabled( false );
// Save the currently selected account for the next logins
defaultHandle_ = handle;
lastUsedHandle_ = handle;
config_.writeEntry( "defaultHandle", handle );
// Find out what status has been chosen
@@ -449,65 +686,165 @@ void InitialView::slotConnectClicked()
default: initialStatus = STATUS_ONLINE; break;
}
// Set the state.
// This toggles reconnection, and "continue connecting" stuff.
triedConnecting_ = true;
// When we connect to an account from outside InitialView, the actual connection
// process may be handled externally, so emitting the signal below would cause
// problems, and even infinite loops.
if( ! emitConnectionSignal )
{
return true;
}
// 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 );
return true;
}
// Change the connection status text
void InitialView::statusMessage( QString text )
void InitialView::statusMessage( const QString text, int timeout )
{
statusLabel_->setText( text );
if( timeout > 0 )
{
statusMessageTimer_.start( timeout );
}
else
{
statusMessageTimer_.stop();
}
}
// Toggle displaying the Options box, which allows remembering accounts & passwords
void InitialView::toggleOptionsBox()
// Execute the browser for a clicked UI link
void InitialView::slotClickedUrl( const QString &url )
{
if( optionsBox_->isHidden() )
// Handle special links
if( url.startsWith( "kmess://" ) )
{
optionsBox_->show();
optionsLabel_->setText( i18nc( "Clickable label on login screen", "Less options..." ) );
if( url == "kmess://reconnect/" )
{
// The reconnection process is still active, stop it before trying to connect
reconnectionTimer_.stop();
startConnecting( reconnectionHandle_ );
}
return;
}
else
KMessShared::openBrowser( KUrl( url ) );
}
bool InitialView::eventFilter(QObject *obj, QEvent *event)
{
// Handle keyboard events for all widgets
if( event->type() == QEvent::KeyPress )
{
optionsBox_->hide();
optionsLabel_->setText( i18nc( "Clickable label on login screen", "More options..." ) );
QKeyEvent *keyEvent = static_cast<QKeyEvent*>( event );
int key = keyEvent->key();
// Enable pressing Enter from any widget to start connecting
if( ( key == Qt::Key_Return || key == Qt::Key_Enter )
|| ( key == Qt::Key_Escape && isConnectingUI_ ) ) // Enable pressing Esc to cancel a connection attempt
{
slotConnectClicked();
return true;
}
}
// The following code is only for the picture label. If any code has to be added for
// another widget, this code may need to be changed..
if( obj != pictureLabel_ )
{
return false; // don't stop processing.
}
// Don't handle events when connecting
if( isConnectingUI_ )
{
return false;
}
Account *account = accounts_[ getSelectedHandle() ];
KStandardDirs *dirs = KGlobal::dirs();
QEvent::Type eventType = event->type();
if( eventType == QEvent::Enter ) // Glow effect when mouse enters display picture
{
QImage glowingImage;
if( account != 0 )
{
glowingImage = QImage( account->getPicturePath() );
}
else
{
glowingImage = QImage( dirs->findResource( "data", "kmess/pics/kmesspic.png" ) );
}
KIconEffect::toGamma( glowingImage, 0.8f );
pictureLabel_->setPixmap( QPixmap::fromImage( glowingImage ) );
}
else if( eventType == QEvent::Leave ) // Restore default when mouse leaves display picture
{
QPixmap picture;
if( account != 0 )
{
picture = QPixmap( account->getPicturePath() );
}
else
{
picture = QPixmap( dirs->findResource( "data", "kmess/pics/kmesspic.png" ) );
}
pictureLabel_->setPixmap( picture );
}
else if( eventType == QEvent::Wheel && handleCombobox_->isEnabled() == true ) // Switch accounts using mousewheel
{
QWheelEvent *wheelEvent = static_cast<QWheelEvent*>( event );
int newIndex = handleCombobox_->currentIndex();
if( wheelEvent->delta() > 0 )
{
newIndex--;
if( newIndex < 0 )
{
newIndex = handleCombobox_->count() - 1;
}
}
else
{
newIndex++;
if( newIndex >= handleCombobox_->count() )
{
newIndex = 0;
}
}
handleCombobox_->setCurrentIndex( newIndex );
}
else if( eventType == QEvent::MouseButtonRelease ) // Show settings when display picture is clicked
{
emit showSettings( account );
}
return false; // don't stop processing.
}