You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
248 lines
6.5 KiB
248 lines
6.5 KiB
#include "systeminstaller.h"
|
|
|
|
#include <QtGui>
|
|
#include <QtGlobal>
|
|
|
|
#include <QIcon>
|
|
#include <QStackedWidget>
|
|
#include <QPushButton>
|
|
#include <QGroupBox>
|
|
#include <QLocale>
|
|
|
|
#include "pagemanager.h"
|
|
|
|
#include "pagewelcome.h"
|
|
#include "pagelicense.h"
|
|
#include "pagepartitioning.h"
|
|
#include "pageconfiguration.h"
|
|
#include "pageinstall.h"
|
|
#include "pagefinish.h"
|
|
|
|
#include "pagecfdisk.h"
|
|
|
|
SystemInstaller::SystemInstaller(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
m_Translator(new QTranslator)
|
|
{
|
|
//m_CurrentLanguage = QLocale::system().name();
|
|
m_CurrentLanguage = QString(qgetenv("LANG")).split(".").first();
|
|
changeLanguage(m_CurrentLanguage);
|
|
|
|
setupUi();
|
|
|
|
setupInstallerPages();
|
|
}
|
|
|
|
SystemInstaller::~SystemInstaller()
|
|
{
|
|
}
|
|
|
|
void SystemInstaller::setupUi()
|
|
{
|
|
QWidget* centralWidget( new QWidget(this) );
|
|
|
|
// buttons
|
|
QHBoxLayout* hbox_buttons( new QHBoxLayout );
|
|
|
|
m_butPrev = new QPushButton;
|
|
m_butNext = new QPushButton;
|
|
m_butFinish = new QPushButton;
|
|
m_butFinish->setVisible(false);
|
|
|
|
hbox_buttons->addStretch();
|
|
hbox_buttons->addWidget( m_butPrev );
|
|
hbox_buttons->addWidget( m_butNext );
|
|
hbox_buttons->addWidget( m_butFinish );
|
|
|
|
// right pannel = widget for pages + buttons
|
|
m_stackPages = new QStackedWidget;
|
|
|
|
QVBoxLayout* vbox_1( new QVBoxLayout );
|
|
QGroupBox* group_box_page( new QGroupBox );
|
|
QVBoxLayout* group_box_page_l( new QVBoxLayout );
|
|
group_box_page_l->addWidget( m_stackPages );
|
|
|
|
group_box_page->setLayout( group_box_page_l );
|
|
|
|
vbox_1->addWidget( group_box_page );
|
|
vbox_1->addLayout( hbox_buttons );
|
|
|
|
// left pannel
|
|
// logo
|
|
m_labelImage = new QLabel;
|
|
m_labelImage->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
|
|
m_labelImage->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
|
|
|
|
m_labelPages = new QLabel;
|
|
|
|
QGroupBox* group_box_list( new QGroupBox );
|
|
QVBoxLayout* group_box_list_l( new QVBoxLayout );
|
|
group_box_list_l->addWidget( m_labelImage );
|
|
group_box_list_l->addWidget( m_labelPages );
|
|
group_box_list_l->addStretch();
|
|
|
|
group_box_list->setLayout( group_box_list_l );
|
|
|
|
// left + right pannels
|
|
QHBoxLayout* hbox_2( new QHBoxLayout );
|
|
hbox_2->addWidget( group_box_list, 2 );
|
|
hbox_2->addLayout( vbox_1, 9);
|
|
|
|
centralWidget->setLayout(hbox_2);
|
|
setCentralWidget( centralWidget );
|
|
|
|
// set windows icon
|
|
QIcon icon( ":/img/calculate-icon.png" );
|
|
setWindowIcon(icon);
|
|
|
|
// minimum size for window TODO: remove magic numbers, add other sizes?
|
|
setMinimumSize(800, 600);
|
|
setMaximumSize(800, 600);
|
|
QRect scr = QApplication::desktop()->screenGeometry();
|
|
move( scr.width() - scr.width()/2 - 800/2, scr.height() - scr.height()/2 - 600/2 );
|
|
|
|
QImage logo = QImage(":/img/calculate-logo.png").scaledToWidth( 120, Qt::SmoothTransformation);
|
|
m_labelImage->setPixmap( QPixmap::fromImage(logo) );
|
|
|
|
retranslateUi();
|
|
}
|
|
|
|
void SystemInstaller::setupInstallerPages()
|
|
{
|
|
// create PageManager and pages
|
|
m_PageManager.reset( new PageManager(m_stackPages, m_labelPages, this) );
|
|
|
|
PageWelcome* pageLanguage( new PageWelcome(&m_CurrentLanguage) );
|
|
connect( pageLanguage, SIGNAL(changeNext(bool)), this, SLOT(changeNext(bool)) );
|
|
connect( pageLanguage, SIGNAL(changeLanguage(QString)), this, SLOT(changeLanguage(QString)) );
|
|
m_PageManager->addPage(pageLanguage);
|
|
|
|
PageLicense* pageLicense( new PageLicense );
|
|
connect( pageLicense, SIGNAL(changeNext(bool)), this, SLOT(changeNext(bool)) );
|
|
m_PageManager->addPage(pageLicense);
|
|
|
|
PagePartitioning* pagePartitoning( new PagePartitioning );
|
|
connect( pagePartitoning, SIGNAL(changeNext(bool)), this, SLOT(changeNext(bool)) );
|
|
connect( pagePartitoning, SIGNAL(manualyPartitioning(QString)), this, SLOT(doPartitioning(QString)) );
|
|
connect( pagePartitoning, SIGNAL(selectedVolume(QString)), this, SLOT(selectVolume(QString)) );
|
|
m_PageManager->addPage(pagePartitoning);
|
|
|
|
PageConfiguration* pageConfiguration( new PageConfiguration(&m_CurrentLanguage) );
|
|
connect( pageConfiguration, SIGNAL(selectedSettings(InstallerSettings)),
|
|
this, SLOT(selectConfiguration(InstallerSettings))
|
|
);
|
|
m_PageManager->addPage(pageConfiguration);
|
|
|
|
PageInstall* pageInstall( new PageInstall( &m_InstallSettings ) );
|
|
connect( pageInstall, SIGNAL(changeNext(bool)), this, SLOT(changeNext(bool)) );
|
|
connect( pageInstall, SIGNAL(changePrev(bool)), this, SLOT(changePrev(bool)) );
|
|
m_PageManager->addPage(pageInstall);
|
|
|
|
PageFinish* pageFinish( new PageFinish );
|
|
connect( pageFinish, SIGNAL(toggleButtons(bool)), this, SLOT(toggleButtons(bool)) );
|
|
m_PageManager->addPage(pageFinish);
|
|
|
|
m_PageManager->showFirst();
|
|
|
|
connect( m_butNext, SIGNAL(clicked()), m_PageManager.data(), SLOT(showNext()) );
|
|
connect( m_butPrev, SIGNAL(clicked()), m_PageManager.data(), SLOT(showPrevious()) );
|
|
connect( m_butFinish, SIGNAL(clicked()), this, SLOT(close()));
|
|
}
|
|
|
|
void SystemInstaller::retranslateUi()
|
|
{
|
|
m_butPrev->setText( tr("Prevoius") );
|
|
m_butNext->setText( tr("Next") );
|
|
m_butFinish->setText( tr("Finish") );
|
|
|
|
if (m_PageManager)
|
|
m_PageManager->retranslatePages();
|
|
}
|
|
|
|
void SystemInstaller::setTranslator(QTranslator* translator)
|
|
{
|
|
removeTranslator();
|
|
m_Translator = translator;
|
|
qApp->installTranslator(translator);
|
|
}
|
|
|
|
void SystemInstaller::removeTranslator()
|
|
{
|
|
if (m_Translator)
|
|
{
|
|
delete m_Translator;
|
|
m_Translator = 0;
|
|
}
|
|
}
|
|
|
|
void SystemInstaller::changeLanguage(QString lang)
|
|
{
|
|
qDebug() << "New language: " + lang;
|
|
|
|
m_CurrentLanguage = lang;
|
|
// QLocale::setDefault( QLocale(lang) );
|
|
|
|
QTranslator* translator( new QTranslator );
|
|
|
|
translator->load("/usr/share/cl-install-gui/cl-install-gui_" + lang);
|
|
qDebug() << "/usr/share/cl-install-gui/cl-install-gui_" + lang + ".qm";
|
|
setTranslator(translator);
|
|
}
|
|
|
|
void SystemInstaller::changeEvent(QEvent* event)
|
|
{
|
|
switch (event->type())
|
|
{
|
|
case QEvent::LanguageChange:
|
|
retranslateUi();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
QWidget::changeEvent(event);
|
|
}
|
|
|
|
|
|
void SystemInstaller::changeNext(bool state)
|
|
{
|
|
m_butNext->setEnabled(state);
|
|
}
|
|
|
|
void SystemInstaller::changePrev(bool state)
|
|
{
|
|
m_butPrev->setEnabled(state);
|
|
}
|
|
|
|
void SystemInstaller::toggleButtons(bool state)
|
|
{
|
|
m_butNext->setVisible(state);
|
|
m_butPrev->setVisible(state);
|
|
m_butFinish->setVisible(!state);
|
|
}
|
|
|
|
void SystemInstaller::selectVolume(QString volume)
|
|
{
|
|
m_InstallSettings.disk = volume;
|
|
}
|
|
|
|
void SystemInstaller::doPartitioning(QString disk)
|
|
{
|
|
m_PageCfdisk = new PageCfdisk( "cfdisk", disk );
|
|
m_PageManager->showOnce(m_PageCfdisk);
|
|
connect( m_PageCfdisk, SIGNAL(completed()), this, SLOT(completePartitioning()) );
|
|
}
|
|
|
|
void SystemInstaller::completePartitioning()
|
|
{
|
|
delete m_PageCfdisk;
|
|
m_PageManager->showPrevious();
|
|
}
|
|
|
|
void SystemInstaller::selectConfiguration(InstallerSettings settings)
|
|
{
|
|
// replace selected volume
|
|
settings.disk = m_InstallSettings.disk;
|
|
m_InstallSettings = settings;
|
|
}
|
|
|