Fix up identifiers + use QComboBox instead of QListView.

This commit is contained in:
Teo Mrnjavac 2015-05-13 12:44:11 +02:00
parent 7bcb060967
commit 3dd1d7932f
7 changed files with 126 additions and 78 deletions

View File

@ -1,12 +1,12 @@
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
calamares_add_plugin( greeting calamares_add_plugin( welcome
TYPE viewmodule TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES SOURCES
GreetingViewStep.cpp WelcomeViewStep.cpp
GreetingPage.cpp WelcomePage.cpp
UI UI
GreetingPage.ui WelcomePage.ui
LINK_LIBRARIES LINK_LIBRARIES
calamaresui calamaresui
SHARED_LIB SHARED_LIB

View File

@ -17,9 +17,9 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "GreetingPage.h" #include "WelcomePage.h"
#include "ui_GreetingPage.h" #include "ui_WelcomePage.h"
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
@ -31,17 +31,18 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QFocusEvent> #include <QFocusEvent>
#include <QLabel> #include <QLabel>
#include <QListWidget> #include <QComboBox>
#include <QMessageBox> #include <QMessageBox>
#include "Branding.h" #include "Branding.h"
GreetingPage::GreetingPage( QWidget* parent ) WelcomePage::WelcomePage( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::GreetingPage ) , ui( new Ui::WelcomePage )
{ {
ui->setupUi( this ); ui->setupUi( this );
ui->languageWidget->setInsertPolicy( QComboBox::InsertAlphabetically );
QLocale defaultLocale = QLocale( QLocale::system().name() ); QLocale defaultLocale = QLocale( QLocale::system().name() );
{ {
@ -55,33 +56,30 @@ GreetingPage::GreetingPage( QWidget* parent )
lang.append( QString( " (%1)" ) lang.append( QString( " (%1)" )
.arg( QLocale::countryToString( thisLocale.country() ) ) ); .arg( QLocale::countryToString( thisLocale.country() ) ) );
ui->languageWidget->addItem( lang ); ui->languageWidget->addItem( lang, thisLocale );
ui->languageWidget->item( ui->languageWidget->count() - 1 )
->setData( Qt::UserRole, thisLocale );
if ( thisLocale.language() == defaultLocale.language() && if ( thisLocale.language() == defaultLocale.language() &&
thisLocale.country() == defaultLocale.country() ) thisLocale.country() == defaultLocale.country() )
{ {
isTranslationAvailable = true; isTranslationAvailable = true;
ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 ); ui->languageWidget->setCurrentIndex( ui->languageWidget->count() - 1 );
cDebug() << "Initial locale " << thisLocale.name(); cDebug() << "Initial locale " << thisLocale.name();
CalamaresUtils::installTranslator( thisLocale, CalamaresUtils::installTranslator( thisLocale.name(),
Calamares::Branding::instance()->translationsPathPrefix(), Calamares::Branding::instance()->translationsPathPrefix(),
qApp ); qApp );
} }
} }
ui->languageWidget->sortItems();
if ( !isTranslationAvailable ) if ( !isTranslationAvailable )
{ {
for (int i = 0; i < ui->languageWidget->count(); i++) for (int i = 0; i < ui->languageWidget->count(); i++)
{ {
QLocale thisLocale = ui->languageWidget->item(i)->data( Qt::UserRole ).toLocale(); QLocale thisLocale = ui->languageWidget->itemData( i, Qt::UserRole ).toLocale();
if ( thisLocale.language() == defaultLocale.language() ) if ( thisLocale.language() == defaultLocale.language() )
{ {
isTranslationAvailable = true; isTranslationAvailable = true;
ui->languageWidget->setCurrentRow( i ); ui->languageWidget->setCurrentIndex( i );
cDebug() << "Initial locale " << thisLocale.name(); cDebug() << "Initial locale " << thisLocale.name();
CalamaresUtils::installTranslator( thisLocale, CalamaresUtils::installTranslator( thisLocale.name(),
Calamares::Branding::instance()->translationsPathPrefix(), Calamares::Branding::instance()->translationsPathPrefix(),
qApp ); qApp );
break; break;
@ -93,13 +91,13 @@ GreetingPage::GreetingPage( QWidget* parent )
{ {
for (int i = 0; i < ui->languageWidget->count(); i++) for (int i = 0; i < ui->languageWidget->count(); i++)
{ {
QLocale thisLocale = ui->languageWidget->item(i)->data( Qt::UserRole ).toLocale(); QLocale thisLocale = ui->languageWidget->itemData( i, Qt::UserRole ).toLocale();
if ( thisLocale == QLocale( QLocale::English, QLocale::UnitedStates ) ) if ( thisLocale == QLocale( QLocale::English, QLocale::UnitedStates ) )
{ {
ui->languageWidget->setCurrentRow( i ); ui->languageWidget->setCurrentIndex( i );
cDebug() << "Translation unavailable, so initial locale set to " << thisLocale.name(); cDebug() << "Translation unavailable, so initial locale set to " << thisLocale.name();
QLocale::setDefault( thisLocale ); QLocale::setDefault( thisLocale );
CalamaresUtils::installTranslator( thisLocale, CalamaresUtils::installTranslator( thisLocale.name(),
Calamares::Branding::instance()->translationsPathPrefix(), Calamares::Branding::instance()->translationsPathPrefix(),
qApp ); qApp );
break; break;
@ -107,10 +105,11 @@ GreetingPage::GreetingPage( QWidget* parent )
} }
} }
connect( ui->languageWidget, &QListWidget::currentItemChanged, connect( ui->languageWidget,
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous ) static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
this, [ & ]( int newIndex )
{ {
QLocale selectedLocale = current->data( Qt::UserRole ).toLocale(); QLocale selectedLocale = ui->languageWidget->itemData( newIndex, Qt::UserRole ).toLocale();
cDebug() << "Selected locale" << selectedLocale.name(); cDebug() << "Selected locale" << selectedLocale.name();
QLocale::setDefault( selectedLocale ); QLocale::setDefault( selectedLocale );
@ -118,12 +117,6 @@ GreetingPage::GreetingPage( QWidget* parent )
Calamares::Branding::instance()->translationsPathPrefix(), Calamares::Branding::instance()->translationsPathPrefix(),
qApp ); qApp );
} ); } );
connect( ui->languageWidget, &QListWidget::itemDoubleClicked,
this, []
{
Calamares::ViewManager::instance()->next();
} );
} }
ui->mainText->setAlignment( Qt::AlignCenter ); ui->mainText->setAlignment( Qt::AlignCenter );
@ -172,7 +165,7 @@ GreetingPage::GreetingPage( QWidget* parent )
void void
GreetingPage::setUpLinks( bool showSupportUrl, WelcomePage::setUpLinks( bool showSupportUrl,
bool showKnownIssuesUrl, bool showKnownIssuesUrl,
bool showReleaseNotesUrl ) bool showReleaseNotesUrl )
{ {
@ -233,7 +226,7 @@ GreetingPage::setUpLinks( bool showSupportUrl,
void void
GreetingPage::focusInEvent( QFocusEvent* e ) WelcomePage::focusInEvent( QFocusEvent* e )
{ {
if ( ui->languageWidget ) if ( ui->languageWidget )
ui->languageWidget->setFocus(); ui->languageWidget->setFocus();

View File

@ -16,21 +16,21 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GREETINGPAGE_H #ifndef WELCOMEPAGE_H
#define GREETINGPAGE_H #define WELCOMEPAGE_H
#include <QWidget> #include <QWidget>
namespace Ui namespace Ui
{ {
class GreetingPage; class WelcomePage;
} }
class GreetingPage : public QWidget class WelcomePage : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GreetingPage( QWidget* parent = nullptr ); explicit WelcomePage( QWidget* parent = nullptr );
void setUpLinks( bool showSupportUrl, void setUpLinks( bool showSupportUrl,
bool showKnownIssuesUrl, bool showKnownIssuesUrl,
@ -40,7 +40,7 @@ protected:
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
private: private:
Ui::GreetingPage* ui; Ui::WelcomePage* ui;
}; };
#endif // GREETINGPAGE_H #endif // WELCOMEPAGE_H

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>GreetingPage</class> <class>WelcomePage</class>
<widget class="QWidget" name="GreetingPage"> <widget class="QWidget" name="WelcomePage">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -15,17 +15,7 @@
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QListWidget" name="languageWidget"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0">
<item> <item>
<spacer name="verticalSpacer_3"> <spacer name="verticalSpacer_3">
<property name="orientation"> <property name="orientation">
@ -81,6 +71,71 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Language:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>languageWidget</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="languageWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>

View File

@ -16,21 +16,21 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "GreetingViewStep.h" #include "WelcomeViewStep.h"
#include "GreetingPage.h" #include "WelcomePage.h"
#include <QVariant> #include <QVariant>
GreetingViewStep::GreetingViewStep( QObject* parent ) WelcomeViewStep::WelcomeViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_widget( new GreetingPage() ) , m_widget( new WelcomePage() )
{ {
emit nextStatusChanged( true ); emit nextStatusChanged( true );
} }
GreetingViewStep::~GreetingViewStep() WelcomeViewStep::~WelcomeViewStep()
{ {
if ( m_widget && m_widget->parent() == nullptr ) if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater(); m_widget->deleteLater();
@ -38,68 +38,68 @@ GreetingViewStep::~GreetingViewStep()
QString QString
GreetingViewStep::prettyName() const WelcomeViewStep::prettyName() const
{ {
return tr( "Welcome" ); return tr( "Welcome" );
} }
QWidget* QWidget*
GreetingViewStep::widget() WelcomeViewStep::widget()
{ {
return m_widget; return m_widget;
} }
void void
GreetingViewStep::next() WelcomeViewStep::next()
{ {
emit done(); emit done();
} }
void void
GreetingViewStep::back() WelcomeViewStep::back()
{} {}
bool bool
GreetingViewStep::isNextEnabled() const WelcomeViewStep::isNextEnabled() const
{ {
return true; return true;
} }
bool bool
GreetingViewStep::isBackEnabled() const WelcomeViewStep::isBackEnabled() const
{ {
return false; return false;
} }
bool bool
GreetingViewStep::isAtBeginning() const WelcomeViewStep::isAtBeginning() const
{ {
return true; return true;
} }
bool bool
GreetingViewStep::isAtEnd() const WelcomeViewStep::isAtEnd() const
{ {
return true; return true;
} }
QList< Calamares::job_ptr > QList< Calamares::job_ptr >
GreetingViewStep::jobs() const WelcomeViewStep::jobs() const
{ {
return QList< Calamares::job_ptr >(); return QList< Calamares::job_ptr >();
} }
void void
GreetingViewStep::setConfigurationMap( const QVariantMap& configurationMap ) WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{ {
bool showSupportUrl = bool showSupportUrl =
configurationMap.contains( "showSupportUrl" ) && configurationMap.contains( "showSupportUrl" ) &&

View File

@ -16,8 +16,8 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef GREETINGPAGEPLUGIN_H #ifndef WELCOMEPAGEPLUGIN_H
#define GREETINGPAGEPLUGIN_H #define WELCOMEPAGEPLUGIN_H
#include <QObject> #include <QObject>
@ -26,9 +26,9 @@
#include <QVariantMap> #include <QVariantMap>
class GreetingPage; class WelcomePage;
class PLUGINDLLEXPORT GreetingViewStep : public Calamares::ViewStep class PLUGINDLLEXPORT WelcomeViewStep : public Calamares::ViewStep
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" ) Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" )
@ -36,8 +36,8 @@ class PLUGINDLLEXPORT GreetingViewStep : public Calamares::ViewStep
Q_INTERFACES( Calamares::ViewStep ) Q_INTERFACES( Calamares::ViewStep )
public: public:
explicit GreetingViewStep( QObject* parent = nullptr ); explicit WelcomeViewStep( QObject* parent = nullptr );
virtual ~GreetingViewStep(); virtual ~WelcomeViewStep();
QString prettyName() const override; QString prettyName() const override;
@ -57,7 +57,7 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override; void setConfigurationMap( const QVariantMap& configurationMap ) override;
private: private:
GreetingPage* m_widget; WelcomePage* m_widget;
}; };
#endif // GREETINGPAGEPLUGIN_H #endif // WELCOMEPAGEPLUGIN_H

View File

@ -1,7 +1,7 @@
# Module metadata file for greeting viewmodule # Module metadata file for welcome viewmodule
# Syntax is YAML 1.2 # Syntax is YAML 1.2
--- ---
type: "view" #core or view type: "view" #core or view
name: "greeting" #the module name. must be unique and same as the parent directory name: "welcome" #the module name. must be unique and same as the parent directory
interface: "qtplugin" #can be: qtplugin, python, process, ... interface: "qtplugin" #can be: qtplugin, python, process, ...
load: "libcalamares_viewmodule_greeting.so" load: "libcalamares_viewmodule_welcome.so"