Commit fd169a25 authored by Ramon Buldó's avatar Ramon Buldó
Browse files

msmlib: format ActionDialog and remove some code

parent 7c53e25f
......@@ -2,6 +2,7 @@
*.pro.user
build
build-debug
build-manjaro-settings-manager-Desktop-Default
build-manjaro-settings-manager-Desktop
build-manjaro-settings-manager-Qt4_Desktop
build-manjaro-settings-manager-Desktop-Debug
......
......@@ -30,54 +30,46 @@
ActionDialog::ActionDialog( QWidget* parent ) :
QDialog( parent )
{
this->setWindowFlags(Qt::SubWindow | Qt::Dialog | Qt::WindowCloseButtonHint);
this->setWindowFlags( Qt::SubWindow | Qt::Dialog | Qt::WindowCloseButtonHint );
QVBoxLayout* vBoxLayout = new QVBoxLayout();
this->setLayout( vBoxLayout );
x = 400;
y = 160;
this->resize( x, y );
window()->setFixedSize(x, y);
window()->setFixedSize( x, y );
m_messageLabel = new QLabel();
vBoxLayout->addWidget( m_messageLabel );
m_messageLabel->setText( tr( "Do you really want to continue?" ) );
m_messageLabel->setWordWrap(true);
m_messageLabel->setWordWrap( true );
m_progressBar = new QProgressBar();
m_progressBar->setMaximum(0);
m_progressBar->setMinimum(0);
vBoxLayout->addWidget(m_progressBar);
m_progressBar->setMaximum( 0 );
m_progressBar->setMinimum( 0 );
vBoxLayout->addWidget( m_progressBar );
m_progressBar->hide();
m_informationLabel = new QLabel();
m_informationLabel->setFixedWidth(x);
vBoxLayout->addWidget( m_informationLabel);
m_informationLabel->setFixedWidth( x );
vBoxLayout->addWidget( m_informationLabel );
QFont f = font();
f.setItalic(true);
f.setItalic( true );
m_informationLabel->setVisible( false );
m_informationLabel->setFont(f);
m_informationLabel->setFont( f );
m_terminal = new QTextEdit();
vBoxLayout->addWidget( m_terminal );
m_terminal->setReadOnly( true );
m_terminal->hide();
m_detailOn = false;
m_showDetails = new QLabel();
m_showDetails->setTextFormat( Qt::RichText );
m_showDetails->setTextInteractionFlags( Qt::TextBrowserInteraction );
m_showDetails->setText( "<a href=\"#show\">" + tr( "Show Details" ) + "</a>" );
m_showDetails->setStyleSheet( "QLabel {color : blue;}" );
f = font();
f.setItalic(false);
f.setUnderline(true);
m_showDetails->setFont(f);
m_showDetails->setCursor(Qt::PointingHandCursor);
vBoxLayout->addWidget( m_showDetails );
QLabel::connect( m_showDetails, &QLabel::linkActivated,
this, &ActionDialog::showDetails );
this, &ActionDialog::showDetails );
this->showDetails( "#hide" );
m_buttonBox = new QDialogButtonBox();
......@@ -94,18 +86,18 @@ ActionDialog::ActionDialog( QWidget* parent ) :
void
ActionDialog::writeToTerminal( const QString& information )
{
m_terminal->append(information);
m_terminal->append( information );
}
void
ActionDialog::showDetails( const QString& link )
{
if ( link == "#hide" )
if ( link == "#hide" )
{
m_terminal -> hide();
m_showDetails->setText( "<a href=\"#show\">" + tr( "Show Details" ) + "</a>" );
m_informationLabel->show();
window()->setFixedSize(x, y);
window()->setFixedSize( x, y );
this->resize( x, y );
}
else if ( link == "#show" )
......@@ -113,8 +105,8 @@ ActionDialog::showDetails( const QString& link )
m_terminal -> show();
m_showDetails->setText( "<a href=\"#hide\">" + tr( "Hide Details" ) + "</a>" );
m_informationLabel->hide();
window()->setFixedSize(x, y + 100);
this->resize(x, y + 100);
window()->setFixedSize( x, y + 100 );
this->resize( x, y + 100 );
}
}
......@@ -124,17 +116,13 @@ ActionDialog::startJob()
m_buttonBox->setStandardButtons( QDialogButtonBox::Close );
m_buttonBox->setDisabled( true );
m_progressBar->show();
m_messageLabel->setText( tr ( "Please wait while your system is being modified" ) );
m_informationLabel->setText( tr ( "Starting" ) );
m_terminal->append( tr ( "Starting" ) );
if (!m_detailOn) {
m_informationLabel->show();
}
KAuth::ExecuteJob* kAuthJob = m_installAction.execute();
connect( kAuthJob, &KAuth::ExecuteJob::newData,
[=] ( const QVariantMap &data )
{
......@@ -143,85 +131,74 @@ ActionDialog::startJob()
{
if ( line != m_lastMessage )
{
QString l = line.remove( QRegularExpression( "\x1b[^m]*m" ));
QString l = line.remove( QRegularExpression( "\x1b[^m]*m" ) );
m_lastMessage = l;
updateInfo ( l );
}
}
} );
connect(kAuthJob, &KAuth::ExecuteJob::result,
[=] ( KJob *kjob )
connect( kAuthJob, &KAuth::ExecuteJob::result,
[=] ( KJob *kjob )
{
auto job = qobject_cast<KAuth::ExecuteJob *>(kjob);
if (job->error() == 0)
jobDone(true, tr ( "Changes failed, click on 'Show Details' for more information" ));
else {
jobDone(false, tr ( "Changes failed, click on 'Show Details' for more information" ));
}
auto job = qobject_cast<KAuth::ExecuteJob*>( kjob );
if ( job->error() == 0 )
jobDone( true, tr ( "Changes failed, click on 'Show Details' for more information" ) );
else
jobDone( false, tr ( "Changes failed, click on 'Show Details' for more information" ) );
} );
connect(kAuthJob, &KAuth::ExecuteJob::statusChanged,
[=] ( KAuth::Action::AuthStatus status )
{
connect( kAuthJob, &KAuth::ExecuteJob::statusChanged,
[=] ( KAuth::Action::AuthStatus status )
{
// switch (status) {
// case KAuth::Action::AuthStatus::DeniedStatus : {
// }
// };
// some error with switch
if (status == KAuth::Action::AuthStatus::DeniedStatus)
{
jobDone (false, tr ( "You are not authorised to make these changes" ));
}
else if (status == KAuth::Action::AuthStatus::ErrorStatus)
{
jobDone (false, tr ( "Some Error occurred during authorization" ));
}
else if (status == KAuth::Action::AuthStatus::InvalidStatus)
{
jobDone (false, tr ( "Invalid authorization status" ));
}
else if (status == KAuth::Action::AuthStatus::UserCancelledStatus)
{
jobDone (false, tr ( "Authorization canceled by you" ));
}
else if (status == KAuth::Action::AuthStatus::AuthorizedStatus)
{
if ( status == KAuth::Action::AuthStatus::DeniedStatus )
jobDone ( false, tr ( "You are not authorised to make these changes" ) );
else if ( status == KAuth::Action::AuthStatus::ErrorStatus )
jobDone ( false, tr ( "Some Error occurred during authorization" ) );
else if ( status == KAuth::Action::AuthStatus::InvalidStatus )
jobDone ( false, tr ( "Invalid authorization status" ) );
else if ( status == KAuth::Action::AuthStatus::UserCancelledStatus )
jobDone ( false, tr ( "Authorization canceled by you" ) );
else if ( status == KAuth::Action::AuthStatus::AuthorizedStatus )
qDebug() << "All good";
}
} );
kAuthJob->start();
}
void
ActionDialog::jobDone (bool success, QString message)
ActionDialog::jobDone ( bool success, QString message )
{
if (success)
if ( success )
{
m_jobSuccesful = true;
if (message != NULL)
if ( message != NULL )
m_messageLabel->setText( tr ( "Changes were made successfully" ) );
else
m_messageLabel->setText( message );
}
else
else
{
m_jobSuccesful = false;
if (message != NULL)
if ( message != NULL )
m_messageLabel->setText( tr ( "Changes failed, click on 'Show Details' for more information" ) );
else
m_messageLabel->setText( message );
}
m_terminal->append( QString( "\n" ) );
m_terminal->append( QString( tr( "Done ..." ) ) );
m_informationLabel->setText( QString( tr( "Done ..." ) ) );
m_buttonBox->setEnabled( true );
m_progressBar->setMaximum(100);
m_progressBar->setValue(100);
m_progressBar->setMaximum( 100 );
m_progressBar->setValue( 100 );
}
bool
......@@ -231,10 +208,10 @@ ActionDialog::isJobSuccesful() const
}
void
ActionDialog::updateInfo(const QString& data)
ActionDialog::updateInfo( const QString& data )
{
writeToTerminal(data);
m_informationLabel->setText(data);
writeToTerminal( data );
m_informationLabel->setText( data );
}
KAuth::Action
......
......@@ -48,11 +48,11 @@ public:
void showDetails( const QString& link );
void writeToTerminal(const QString& infomation);
void updateInfo (const QString& data);
void jobDone (bool success, QString message = NULL);
void writeToTerminal( const QString& infomation );
void updateInfo ( const QString& data );
void jobDone ( bool success, QString message = NULL );
private:
void startJob();
......@@ -70,8 +70,6 @@ private:
QString m_lastMessage;
bool m_detailOn;
int x, y;
};
......
......@@ -52,7 +52,7 @@ KeyboardPage::KeyboardPage( QWidget* parent ) :
static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
[=] ( int index )
{
Q_UNUSED(index);
Q_UNUSED( index );
QString model = ui->modelComboBox->itemData(
ui->modelComboBox->currentIndex(),
KeyboardModel::KeyRole )
......
......@@ -213,7 +213,7 @@ LanguagePackagesCommon::installPackages( Ui::PageLanguagePackages* ui )
ActionDialog actionDialog;
actionDialog.setInstallAction( installAction );
actionDialog.setWindowTitle( tr( "Install language packages." ) );
actionDialog.writeToTerminal( QString( tr( "Waiting for user input..." )));
actionDialog.writeToTerminal( QString( tr( "Waiting for user input..." ) ) );
actionDialog.exec();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment