Initial commit for the locale viewmodule.

This commit is contained in:
Teo Mrnjavac 2014-07-02 17:59:24 +02:00
parent 3a58e2640f
commit 1ac10b40e6
92 changed files with 1073 additions and 1 deletions

View File

@ -11,5 +11,5 @@ modules-search: [ local, /path/to/dir/with/more/modules ]
# TBD: do we want to allow non-page modules (core-modules) to be set as immediate or
# delayed? Is this an intrinsic property of a module? Does it depend on whether it's
# a QProcess, a Python script or a plugin? More research is required. --teo
modules-prepare : [ greeting, partition ]
modules-prepare : [ greeting, locale, partition ]
modules-postinstall : [ finished ]

View File

@ -0,0 +1,15 @@
include_directories( ${PROJECT_BINARY_DIR}/src/calamares )
calamares_add_plugin( locale
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
CONFIG_FILE module.conf
SOURCES
LocaleViewStep.cpp
LocalePage.cpp
timezonewidget/timezonewidget.cpp
timezonewidget/localeglobal.cpp
UI
LINK_LIBRARIES
${CALAMARES_LIBRARIES}
SHARED_LIB
)

View File

@ -0,0 +1,141 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LocalePage.h"
#include "timezonewidget/timezonewidget.h"
#include <QBoxLayout>
#include <QComboBox>
#include <QLabel>
LocalePage::LocalePage( QWidget* parent )
: QWidget()
, m_blockTzWidgetSet( false )
{
QBoxLayout *mainLayout = new QVBoxLayout;
m_tzWidget = new TimeZoneWidget( this );
mainLayout->addWidget( m_tzWidget );
QBoxLayout *bottomLayout = new QHBoxLayout;
mainLayout->addLayout( bottomLayout );
QLabel* cityLabel = new QLabel( tr( "Region:" ), this );
bottomLayout->addWidget( cityLabel );
m_regionCombo = new QComboBox( this );
bottomLayout->addWidget( m_regionCombo );
m_regionCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
cityLabel->setBuddy( m_regionCombo );
bottomLayout->addSpacing( 20 );
QLabel* timezoneLabel = new QLabel( tr( "Zone:" ), this );
bottomLayout->addWidget( timezoneLabel );
m_timezoneCombo = new QComboBox( this );
m_timezoneCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
bottomLayout->addWidget( m_timezoneCombo );
timezoneLabel->setBuddy( m_timezoneCombo );
mainLayout->addStretch();
setLayout( mainLayout );
connect( m_regionCombo,
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
[this]( const QString& current )
{
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
if ( !regions.contains( current ) )
return;
m_timezoneCombo->blockSignals( true );
m_timezoneCombo->clear();
QList< LocaleGlobal::Location > zones = regions.value( current );
foreach ( const LocaleGlobal::Location& zone, zones )
{
m_timezoneCombo->addItem( zone.zone );
}
m_timezoneCombo->model()->sort( 0 );
m_timezoneCombo->blockSignals( false );
m_timezoneCombo->currentIndexChanged( m_timezoneCombo->currentText() );
});
connect( m_timezoneCombo,
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
[this]( const QString& current )
{
if ( !m_blockTzWidgetSet )
m_tzWidget->setCurrentLocation( m_regionCombo->currentText(), current );
});
connect( m_tzWidget, &TimeZoneWidget::locationChanged,
[this]( LocaleGlobal::Location location )
{
m_blockTzWidgetSet = true;
// Set region index
int index = m_regionCombo->findText( location.region );
if ( index < 0 )
return;
m_regionCombo->setCurrentIndex( index );
// Set zone index
index = m_timezoneCombo->findText( location.zone );
if ( index < 0 )
return;
m_timezoneCombo->setCurrentIndex( index );
m_blockTzWidgetSet = false;
});
}
void
LocalePage::init()
{
m_regionCombo->blockSignals( true );
m_timezoneCombo->blockSignals( true );
// Setup locations
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
QStringList keys = regions.keys();
keys.sort();
foreach ( const QString& key, keys )
{
m_regionCombo->addItem( key );
}
m_regionCombo->blockSignals( false );
m_timezoneCombo->blockSignals( false );
m_regionCombo->currentIndexChanged( m_regionCombo->currentText() );
}

View File

@ -0,0 +1,43 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOCALEPAGE_H
#define LOCALEPAGE_H
#include <QWidget>
class QComboBox;
class TimeZoneWidget;
class LocalePage : public QWidget
{
Q_OBJECT
public:
explicit LocalePage( QWidget* parent = nullptr );
void init();
private:
TimeZoneWidget* m_tzWidget;
QComboBox* m_regionCombo;
QComboBox* m_timezoneCombo;
bool m_blockTzWidgetSet;
};
#endif // LOCALEPAGE_H

View File

@ -0,0 +1,88 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LocaleViewStep.h"
#include "LocalePage.h"
#include "timezonewidget/localeglobal.h"
LocaleViewStep::LocaleViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new LocalePage() )
{
LocaleGlobal::init(); //this takes a long time
m_widget->init();
emit nextStatusChanged( true );
}
LocaleViewStep::~LocaleViewStep()
{
if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater();
}
QString
LocaleViewStep::prettyName() const
{
return tr( "Location" );
}
QWidget*
LocaleViewStep::widget()
{
return m_widget;
}
void
LocaleViewStep::next()
{
//TODO: actually save those settings somewhere
emit done();
}
void
LocaleViewStep::back()
{}
bool
LocaleViewStep::isNextEnabled() const
{
return true;
}
bool
LocaleViewStep::isAtBeginning() const
{
return true;
}
bool
LocaleViewStep::isAtEnd() const
{
return true;
}

View File

@ -0,0 +1,56 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOCALEVIEWSTEP_H
#define LOCALEVIEWSTEP_H
#include <QObject>
#include "viewpages/ViewStep.h"
#include "PluginDllMacro.h"
class LocalePage;
class PLUGINDLLEXPORT LocaleViewStep : public Calamares::ViewStep
{
Q_OBJECT
Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" )
Q_INTERFACES( Calamares::ViewStep )
public:
explicit LocaleViewStep( QObject* parent = nullptr );
virtual ~LocaleViewStep();
QString prettyName() const override;
QWidget* widget() override;
void next() override;
void back() override;
bool isNextEnabled() const override;
bool isAtBeginning() const override;
bool isAtEnd() const override;
private:
LocalePage* m_widget;
};
#endif // LOCALEVIEWSTEP_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 911 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -0,0 +1,8 @@
# Module metadata file for locale viewmodule
# Syntax is YAML 1.2
---
type: "view"
name: "locale"
interface: "qtplugin"
requires: []
load: "libcalamares_viewmodule_locale.so"

View File

@ -0,0 +1,44 @@
<RCC>
<qresource prefix="/">
<file>images/bg.png</file>
<file>images/pin.png</file>
<file>images/timezone_0.0.png</file>
<file>images/timezone_1.0.png</file>
<file>images/timezone_2.0.png</file>
<file>images/timezone_3.0.png</file>
<file>images/timezone_3.5.png</file>
<file>images/timezone_4.0.png</file>
<file>images/timezone_4.5.png</file>
<file>images/timezone_5.0.png</file>
<file>images/timezone_5.5.png</file>
<file>images/timezone_5.75.png</file>
<file>images/timezone_6.0.png</file>
<file>images/timezone_6.5.png</file>
<file>images/timezone_7.0.png</file>
<file>images/timezone_8.0.png</file>
<file>images/timezone_9.0.png</file>
<file>images/timezone_9.5.png</file>
<file>images/timezone_10.0.png</file>
<file>images/timezone_10.5.png</file>
<file>images/timezone_11.0.png</file>
<file>images/timezone_11.5.png</file>
<file>images/timezone_12.0.png</file>
<file>images/timezone_12.75.png</file>
<file>images/timezone_13.0.png</file>
<file>images/timezone_-1.0.png</file>
<file>images/timezone_-2.0.png</file>
<file>images/timezone_-3.0.png</file>
<file>images/timezone_-3.5.png</file>
<file>images/timezone_-4.0.png</file>
<file>images/timezone_-4.5.png</file>
<file>images/timezone_-5.0.png</file>
<file>images/timezone_-5.5.png</file>
<file>images/timezone_-6.0.png</file>
<file>images/timezone_-7.0.png</file>
<file>images/timezone_-8.0.png</file>
<file>images/timezone_-9.0.png</file>
<file>images/timezone_-9.5.png</file>
<file>images/timezone_-10.0.png</file>
<file>images/timezone_-11.0.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,33 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org>
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOCALECONST_H
#define LOCALECONST_H
#define LOCALESDIR "/usr/share/i18n/locales"
#define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab"
#define XKB_FILE "/usr/share/X11/xkb/rules/base.lst"
#define USER_IMAGES_PATH "/usr/share/pixmaps/faces"
#endif // LOCALECONST_H

View File

@ -0,0 +1,305 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org>
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "localeglobal.h"
//###
//### Private variables
//###
QHash<QString, QHash<QString, QList<LocaleGlobal::Locale> > > LocaleGlobal::locales;
QHash<QString, QList<LocaleGlobal::Location> > LocaleGlobal::locations;
//###
//### Public methods
//###
void LocaleGlobal::init() {
// TODO: Error handling
initLocales();
initLocations();
}
QHash<QString, QHash<QString, QList<LocaleGlobal::Locale> > > LocaleGlobal::getLocales() {
return locales;
}
QHash<QString, QList<LocaleGlobal::Location> > LocaleGlobal::getLocations() {
return locations;
}
QMap<QString, LocaleGlobal::KeyboardInfo> LocaleGlobal::getKeyboardLayouts() {
return parseKeyboardLayouts(XKB_FILE);
}
QMap<QString, QString> LocaleGlobal::getKeyboardModels() {
return parseKeyboardModels(XKB_FILE);
}
//###
//### Private methods
//###
void LocaleGlobal::initLocales() {
locales.clear();
QStringList files = QDir(LOCALESDIR).entryList(QDir::Files, QDir::Name);
for (int i = 0; i < files.size(); ++i) {
QString filename = files.at(i);
QFile file(QString(LOCALESDIR) + "/" + filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
continue;
QTextStream in(&file);
QString commentChar = "%";
Locale locale;
QString lang, territory;
locale.locale = filename;
while (!in.atEnd()) {
QString line = in.readLine().trimmed();
QStringList split = line.split(commentChar, QString::KeepEmptyParts).first().split(QRegExp(" (?=[^\"]*(\"[^\"]*\"[^\"]*)*$)"), QString::SkipEmptyParts);
if (split.size() < 2)
continue;
QString sub1 = QString(split.at(0)).remove("\"");
QString sub2 = QString(split.at(1)).remove("\"");
if (sub1 == "comment_char")
commentChar = sub2;
else if (sub1 == "title")
locale.description = sub2;
else if (sub1 == "territory")
territory= sub2;
else if (sub1 == "language")
lang = sub2;
}
if (lang.isEmpty() || territory.isEmpty())
continue;
locales[lang][territory].append(locale);
}
}
void LocaleGlobal::initLocations() {
locations.clear();
QFile file(TZ_DATA_FILE);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine().trimmed().split('#', QString::KeepEmptyParts).first().trimmed();
if (line.isEmpty())
continue;
QStringList list = line.split(QRegExp("[\t ]"), QString::SkipEmptyParts);
if (list.size() < 3)
continue;
Location location;
QStringList timezone = list.at(2).split('/', QString::SkipEmptyParts);
int cooSplitPos = QString(list.at(1)).remove(0, 1).indexOf(QRegExp("[-+]")) + 1;
if (timezone.size() < 2)
continue;
location.region = timezone.first();
location.zone = timezone.last();
location.latitude = getRightGeoLocation(list.at(1).mid(0, cooSplitPos));
location.longitude = getRightGeoLocation(list.at(1).mid(cooSplitPos));
locations[location.region].append(location);
}
}
double LocaleGlobal::getRightGeoLocation(QString str) {
double sign = 1, num = 0.00;
// Determind sign
if (str.startsWith('-')) {
sign = -1;
str.remove(0, 1);
}
else if (str.startsWith('+')) {
str.remove(0, 1);
}
if (str.length() == 4 || str.length() == 6)
num = str.mid(0, 2).toDouble() + str.mid(2, 2).toDouble() / 60;
else if (str.length() == 5 || str.length() == 7)
num = str.mid(0, 3).toDouble() + str.mid(3, 2).toDouble() / 60;
return sign * num;
}
//### Source by Georg Grabler <ggrabler@gmail.com> ###//
QMap<QString, QString> LocaleGlobal::parseKeyboardModels(QString filepath)
{
QMap<QString, QString> models;
QFile fh(filepath);
fh.open(QIODevice::ReadOnly);
if (!fh.isOpen()) {
qDebug() << "X11 Keyboard model definitions not found!";
return models;
}
bool modelsFound = false;
// read the file until the end or until we break the loop
while (!fh.atEnd()) {
QByteArray line = fh.readLine();
// check if we start with the model section in the file
if (!modelsFound && line.startsWith("! model"))
modelsFound = true;
else if (modelsFound && line.startsWith ("!"))
break;
else if (!modelsFound)
continue;
// here we are in the model section, otherwhise we would continue or break
QRegExp rx;
rx.setPattern("^\\s+(\\S+)\\s+(\\w.*)\n$");
// insert into the model map
if (rx.indexIn(line) != -1) {
QString modelDesc = rx.cap(2);
QString model = rx.cap(1);
if (model == "pc105")
modelDesc += " - " + QObject::tr("Default Keyboard Model");
models.insert(modelDesc, model);
}
}
return models;
}
QMap< QString, LocaleGlobal::KeyboardInfo > LocaleGlobal::parseKeyboardLayouts(QString filepath)
{
QMap< QString, KeyboardInfo > layouts;
//### Get Layouts ###//
QFile fh(filepath);
fh.open(QIODevice::ReadOnly);
if (!fh.isOpen()) {
qDebug() << "X11 Keyboard layout definitions not found!";
return layouts;
}
bool layoutsFound = false;
// read the file until the end or we break the loop
while (!fh.atEnd()) {
QByteArray line = fh.readLine();
// find the layout section otherwhise continue. If the layout section is at it's end, break the loop
if (!layoutsFound && line.startsWith("! layout"))
layoutsFound = true;
else if (layoutsFound && line.startsWith ("!"))
break;
else if (!layoutsFound)
continue;
QRegExp rx;
rx.setPattern("^\\s+(\\S+)\\s+(\\w.*)\n$");
// insert into the layout map
if (rx.indexIn(line) != -1) {
KeyboardInfo info;
info.description = rx.cap(2);
info.variants.insert(QObject::tr("Default"), "");
layouts.insert(rx.cap(1), info);
}
}
fh.reset();
//### Get Variants ###//
bool variantsFound = false;
// read the file until the end or until we break
while (!fh.atEnd()) {
QByteArray line = fh.readLine();
// continue until we found the variant section. If found, read until the next section is found
if (!variantsFound && line.startsWith("! variant")) {
variantsFound = true;
continue;
} else if (variantsFound && line.startsWith ("!"))
break;
else if (!variantsFound)
continue;
QRegExp rx;
rx.setPattern("^\\s+(\\S+)\\s+(\\S+): (\\w.*)\n$");
// insert into the variants multimap, if the pattern matches
if (rx.indexIn(line) != -1) {
if (layouts.find(rx.cap(2)) != layouts.end()) {
// in this case we found an entry in the multimap, and add the values to the multimap
layouts.find(rx.cap(2)).value().variants.insert(rx.cap(3), rx.cap(1));
} else {
// create a new map in the multimap - the value was not found.
KeyboardInfo info;
info.description = rx.cap(2);
info.variants.insert(QObject::tr("Default"), "");
info.variants.insert(rx.cap(3), rx.cap(1));
layouts.insert(rx.cap(2), info);
}
}
}
return layouts;
}

View File

@ -0,0 +1,74 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org>
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOCALEGLOBAL_H
#define LOCALEGLOBAL_H
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QDir>
#include <QStringList>
#include <QList>
#include <QHash>
#include <QMap>
#include <QRegExp>
#include <QDebug>
#include "localeconst.h"
class LocaleGlobal
{
public:
struct Locale {
QString description, locale;
};
struct Location {
QString region, zone;
double latitude, longitude;
};
struct KeyboardInfo {
QString description;
QMap< QString, QString > variants;
};
static void init();
static QHash<QString, QHash<QString, QList<LocaleGlobal::Locale> > > getLocales();
static QHash<QString, QList<LocaleGlobal::Location> > getLocations();
static QMap< QString, KeyboardInfo > getKeyboardLayouts();
static QMap<QString, QString> getKeyboardModels();
private:
static QHash<QString, QHash<QString, QList<LocaleGlobal::Locale> > > locales;
static QHash<QString, QList<LocaleGlobal::Location> > locations;
static void initLocales();
static void initLocations();
static double getRightGeoLocation(QString str);
static QMap<QString, QString> parseKeyboardModels(QString filepath);
static QMap< QString, KeyboardInfo > parseKeyboardLayouts(QString filepath);
};
#endif // LOCALEGLOBAL_H

View File

@ -0,0 +1,193 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org>
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "timezonewidget.h"
TimeZoneWidget::TimeZoneWidget(QWidget *parent) :
QWidget(parent)
{
setMouseTracking(false);
setCursor(Qt::PointingHandCursor);
// Font
font.setFamily("Cantarell");
font.setPointSize(12);
font.setBold(false);
// Images
background = QImage(":/images/bg.png").scaled(X_SIZE, Y_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pin = QImage(":/images/pin.png");
// Set size
setMinimumSize(background.size());
setMaximumSize(background.size());
// Zone images
QStringList zones = QString(ZONES).split(" ", QString::SkipEmptyParts);
for (int i = 0; i < zones.size(); ++i)
timeZoneImages.append(QImage(":/images/timezone_" + zones.at(i) + ".png").scaled(X_SIZE, Y_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
void TimeZoneWidget::setCurrentLocation(QString region, QString zone) {
QHash<QString, QList<LocaleGlobal::Location> > hash = LocaleGlobal::getLocations();
if (!hash.contains(region))
return;
QList<LocaleGlobal::Location> locations = hash.value(region);
for (int i = 0; i < locations.size(); ++i) {
if (locations.at(i).zone == zone) {
setCurrentLocation(locations.at(i));
break;
}
}
}
void TimeZoneWidget::setCurrentLocation(LocaleGlobal::Location location) {
currentLocation = location;
// Set zone
QPoint pos = getLocationPosition(currentLocation.longitude, currentLocation.latitude);
for (int i = 0; i < timeZoneImages.size(); ++i) {
QImage zone = timeZoneImages[i];
// If not transparent set as current
if (zone.pixel(pos) != RGB_TRANSPARENT) {
currentZoneImage = zone;
break;
}
}
// Repaint widget
repaint();
}
//###
//### Private
//###
QPoint TimeZoneWidget::getLocationPosition(double longitude, double latitude) {
const int width = this->width();
const int height = this->height();
double x = (width / 2.0 + (width / 2.0) * longitude / 180.0) + MAP_X_OFFSET * width;
double y = (height / 2.0 - (height / 2.0) * latitude / 90.0) + MAP_Y_OFFSET * height;
if (x < 0)
x = width+x;
if (x >= width)
x -= width;
if (y < 0)
y = height+y;
if (y >= height)
y -= height;
return QPoint((int)x, (int)y);
}
void TimeZoneWidget::paintEvent(QPaintEvent*) {
const int width = this->width();
const int height = this->height();
QFontMetrics fontMetrics(font);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setFont(font);
// Draw background
painter.drawImage(0, 0, background);
// Draw zone image
painter.drawImage(0, 0, currentZoneImage);
// Draw pin
QPoint point = getLocationPosition(currentLocation.longitude, currentLocation.latitude);
painter.drawImage(point.x() - pin.width()/2, point.y() - pin.height()/2, pin);
// Draw text and box
const int textWidth = fontMetrics.width(currentLocation.zone);
const int textHeight = fontMetrics.height();
QRect rect = QRect(point.x() - textWidth/2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2);
if (rect.x() <= 5)
rect.moveLeft(5);
if (rect.right() >= width-5)
rect.moveRight(width - 5);
if (rect.y() <= 5)
rect.moveTop(5);
if (rect.y() >= height-5)
rect.moveBottom(height-5);
painter.setPen(QPen()); // no pen
painter.setBrush(QColor(40, 40, 40));
painter.drawRoundedRect(rect, 3, 3);
painter.setPen(Qt::white);
painter.drawText(rect.x() + 5, rect.bottom() - 4, currentLocation.zone);
painter.end();
}
void TimeZoneWidget::mousePressEvent(QMouseEvent *event) {
if (event->button() != Qt::LeftButton)
return;
// Set nearest location
int nX = 999999, mX = event->pos().x();
int nY = 999999, mY = event->pos().y();
QHash<QString, QList<LocaleGlobal::Location> > hash = LocaleGlobal::getLocations();
QHash<QString, QList<LocaleGlobal::Location> >::iterator iter = hash.begin();
while (iter != hash.end()) {
QList<LocaleGlobal::Location> locations = iter.value();
for (int i = 0; i < locations.size(); ++i) {
LocaleGlobal::Location loc = locations[i];
QPoint locPos = getLocationPosition(loc.longitude, loc.latitude);
if ((abs(mX - locPos.x()) + abs(mY - locPos.y()) < abs(mX - nX) + abs(mY - nY))) {
currentLocation = loc;
nX = locPos.x();
nY = locPos.y();
}
}
++iter;
}
// Set zone image and repaint widget
setCurrentLocation(currentLocation);
// Emit signal
emit locationChanged(currentLocation);
}

View File

@ -0,0 +1,72 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org>
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TIMEZONEWIDGET_H
#define TIMEZONEWIDGET_H
#include <QWidget>
#include <QPainter>
#include <QImage>
#include <QFile>
#include <QTextStream>
#include <QList>
#include <QStringList>
#include <QMouseEvent>
#include <QFontMetrics>
#include <QFont>
#include "localeglobal.h"
#define MAP_Y_OFFSET 0.125
#define MAP_X_OFFSET -0.0370
#define RGB_TRANSPARENT 0
#define ZONES "0.0 1.0 2.0 3.0 3.5 4.0 4.5 5.0 5.5 5.75 6.0 6.5 7.0 8.0 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.75 13.0 -1.0 -2.0 -3.0 -3.5 -4.0 -4.5 -5.0 -5.5 -6.0 -7.0 -8.0 -9.0 -9.5 -10.0 -11.0"
#define X_SIZE 780
#define Y_SIZE 340
class TimeZoneWidget : public QWidget
{
Q_OBJECT
public:
explicit TimeZoneWidget(QWidget *parent = 0);
LocaleGlobal::Location getCurrentLocation() { return currentLocation; }
void setCurrentLocation(QString region, QString zone);
void setCurrentLocation(LocaleGlobal::Location location);
signals:
void locationChanged(LocaleGlobal::Location location);
private:
QFont font;
QImage background, pin, currentZoneImage;
QList<QImage> timeZoneImages;
LocaleGlobal::Location currentLocation;
QPoint getLocationPosition(double longitude, double latitude);
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
};
#endif // TIMEZONEWIDGET_H