Compare commits

..

37 Commits

Author SHA1 Message Date
Adriaan de Groot
5ea2e1c2fe [locale] Fix QString-vs-char* confusion 2018-05-17 23:19:00 +02:00
Adriaan de Groot
c9ced8c387 ci: switch to less volatile KDE Neon version 2018-04-26 10:10:05 -04:00
Adriaan de Groot
4f16d65a8b CMake: bump version 2018-04-13 09:59:16 -04:00
Adriaan de Groot
17fd10cdb1 [locale] Un-idiomize back to 3.1 2018-04-13 09:44:17 -04:00
Adriaan de Groot
faf21ce438 [locale] Log GeoIP attempt URL, use possibly-modified form 2018-04-13 09:43:46 -04:00
Adriaan de Groot
be5ad6944e [locale] On GeoIP failure, log URL 2018-04-13 09:43:46 -04:00
Adriaan de Groot
c9928c99c8 Merge remote-tracking branch 'origin/3.1.x-stable' into 3.1.x-stable 2018-04-12 17:13:34 -04:00
Adriaan de Groot
1340613ef5 [locale] Additional test application for GeoIP processing 2018-04-12 16:55:24 -04:00
Adriaan de Groot
76e37402b3 [locale] Extend tests with negative results 2018-04-12 16:23:54 -04:00
Adriaan de Groot
0c1453ff18 [locale] Fix string value handled by XML parser 2018-04-12 16:23:54 -04:00
Adriaan de Groot
eea421f499 [locale] Add tests for GeoIP handlers
- One sample JSON result
 - Two sample XML results
2018-04-12 16:23:54 -04:00
Adriaan de Groot
6b7c8a694a [locale] Make the style of GeoIP retrieval selectable
- Unchanged config files will continue to use the weird addition
   of /json, and interpret JSON data.
 - Allow to specify full URL with data format through one of
     geoipStyle: json
     geoipStyle: xml
 - XML support is optional
2018-04-12 14:37:38 -04:00
Adriaan de Groot
5b98e58ae7 [locale] Refactor GeoIP handlers
- Read the data in the caller of the handler, instead of in the callers
2018-04-12 12:22:43 -04:00
Adriaan de Groot
939cdff93b [locale] Add alternate GeoIP data format 2018-04-12 12:18:43 -04:00
Adriaan de Groot
aaae1507cd [locale] Convenience function for TZ splitting 2018-04-12 11:51:50 -04:00
Adriaan de Groot
3636226425 [locale] Document change to the way GeoIPURL is handled. 2018-04-12 10:18:15 -04:00
Adriaan de Groot
fe98b789f0 [locale] Document the settings in locale.conf
- The geoipUrl is weird, because it is not a complete URL.
   Document that, and what kind of data is expected.

FIXES #920
2018-04-12 10:15:19 -04:00
Adriaan de Groot
d5623af8ef [locale] Refactor geoip handling
- Configuration **must** be a complete URL. The implementation no
   longer appends /json to the URL.
2018-04-12 10:11:48 -04:00
Adriaan de Groot
c0d5a153d4 [locale] Refactor GeoIP handler
- Move GeoIP to its own cpp file
 - Provide a default implementation of the URL mangler
2018-04-12 09:54:22 -04:00
Adriaan de Groot
445f181cc3 [locale] Start refactoring geoip handling
- Introduce a handler interface for GeoIP providers
 - Move the implementation of FreeGeoIP into a struct of its own
2018-04-12 09:45:48 -04:00
Adriaan de Groot
06e43a7312 CI: Switch to stable Neon, to avoid all-builds-failing.
The dev-unstable Neon branch now has a too-new KPMCore for
this branch of Calamares.
2018-04-09 11:20:40 -04:00
Adriaan de Groot
b8e6144553 [locale] Document how the locale entry in Global Storage works.
- Make the BCP47 value explicitly lower-case.
 - Add some constness and encapsulation.
 - Fix up documentation in the packages module explaining the
   format of the ${LOCALE} replacement (now forced to lower-case,
   but it is also only the language part, not e.g. en-UK).

FIXES #922
2018-04-03 13:07:36 -04:00
Adriaan de Groot
4c04260b97 [packages] Don't change the global package list.
- Count only the packages that will be changed, given the current
   locale settings.
 - Preserve global storage unchanged (don't remove any locale-packages).
2018-04-03 08:28:29 -04:00
Adriaan de Groot
36aede52ef [packages] Example configuration installs a localization package 2018-04-03 08:20:01 -04:00
Adriaan de Groot
fd1279dbe3 [welcome] Make the example configuration less strict 2018-04-03 08:19:45 -04:00
Adriaan de Groot
9cdb6734bf [packages] If locale is empty, pretend it is 'en'.
- Otherwise packages like vi-$LOCALE will be retained in the
   package list, which will cause install problems.
2018-04-03 08:02:16 -04:00
Adriaan de Groot
32a1c84935 [locale] Document the settings in locale.conf
- The geoipUrl is weird, because it is not a complete URL.
   Document that, and what kind of data is expected.

FIXES #920
2018-03-29 16:50:02 -04:00
Adriaan de Groot
fb93a8288e [plasmalnf] Simplify showAll handling
- Only need the showAll parameter once, when passing in the list
   of themes to show.
2018-03-29 10:09:45 -04:00
Adriaan de Groot
b0828faadb [plasmalnf] New setting to show all installed LnF themes
- This enables working in three modes:
   - No themes listed; all are shown without screenshots,
   - Themes listed, showAll false; only those are shown,
   - Themes listed, showAll true; the installed-but-not-listed
     themes are shown after the listed ones, and have limited info.
2018-03-29 09:57:19 -04:00
Adriaan de Groot
c2efae765d [plasmalnf] Add auto-detection of Plasma theme.
- Although it's not necessarily accurate for an extensively-modified
   Plasma configuration, we can read the Look-and-Feel from the
   configuration files. Allows auto-detection.
2018-03-29 08:49:22 -04:00
Adriaan de Groot
11652c5856 [plasmalnf] Add pre-selected theme
- For OEM modes where there is already a theme, add a preselect:
   key to pick a specific theme and have that one come up as already-
   selected in the list.
 - Don't re-run the lnftool if an already-selected theme is clicked
   again. Use toggled() instead of clicked().
2018-03-29 07:59:16 -04:00
Adriaan de Groot
94000b6847 [plasmalnf] Improve wording of LnF explanation. 2018-03-29 04:33:55 -04:00
Adriaan de Groot
b3f0932ff9 CMake: bump version number 2018-01-02 15:37:36 +01:00
Adriaan de Groot
41e6f0e06c [calamares] Allow WM close button
- remove hide-close-button hack
 - refactor code in viewmanager for confirming quit
 - hook up confirm-and-quit to WM close button
 - also works for alt-F4 and other quit methods
 - while here, update copyright year

FIXES #870
2018-01-02 14:58:08 +01:00
Adriaan de Groot
5593be125f [calamares] Reduce font-related debug output on startup. 2018-01-02 14:43:48 +01:00
Adriaan de Groot
661789825a [plasmalnf] Make the module optional
- Check for presence of KDE Frameworks for Plasma & Package
 - Explain when module is skipped
2017-12-24 16:15:04 -05:00
Adriaan de Groot
2e1f389997 CMake: explain which modules are skipped
Modules may be skipped for different reasons: SKIP_MODULES
is the traditional approach to suppress some, but other modules
may have unmet build requirements (e.g. Plasma Look-and-Feel,
or the Partitioning module) and should be able to opt-out
of being built. For all those skipped, log it explicitly after
all the modules have been examined.

Only CMake-based (e.g. C++) modules support opting-out in this way.
2017-12-24 16:14:58 -05:00
35 changed files with 966 additions and 144 deletions

View File

@@ -176,7 +176,7 @@ set( CALAMARES_TRANSLATION_LANGUAGES ar ast bg ca cs_CZ da de el en en_GB es_MX
### Bump version here
set( CALAMARES_VERSION_MAJOR 3 )
set( CALAMARES_VERSION_MINOR 1 )
set( CALAMARES_VERSION_PATCH 11 )
set( CALAMARES_VERSION_PATCH 13 )
set( CALAMARES_VERSION_RC 0 )
set( CALAMARES_VERSION ${CALAMARES_VERSION_MAJOR}.${CALAMARES_VERSION_MINOR}.${CALAMARES_VERSION_PATCH} )

View File

@@ -3,15 +3,27 @@ include( CalamaresAddTranslations )
set( MODULE_DATA_DESTINATION share/calamares/modules )
# Convenience function to indicate that a module has been skipped
# (optionally also why). Call this in the module's CMakeLists.txt
macro( calamares_skip_module )
set( SKIPPED_MODULES ${SKIPPED_MODULES} ${ARGV} PARENT_SCOPE )
endmacro()
function( calamares_add_module_subdirectory )
set( SUBDIRECTORY ${ARGV0} )
set( SKIPPED_MODULES )
set( MODULE_CONFIG_FILES "" )
# If this subdirectory has a CMakeLists.txt, we add_subdirectory it...
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt" )
add_subdirectory( ${SUBDIRECTORY} )
file( GLOB MODULE_CONFIG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY} "${SUBDIRECTORY}/*.conf" )
# Module has indicated it should be skipped, show that in
# the calling CMakeLists (which is src/modules/CMakeLists.txt normally).
if ( SKIPPED_MODULES )
set( SKIPPED_MODULES ${SKIPPED_MODULES} PARENT_SCOPE )
endif()
# ...otherwise, we look for a module.desc.
elseif( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/module.desc" )
set( MODULES_DIR ${CMAKE_INSTALL_LIBDIR}/calamares/modules )

View File

@@ -1,2 +1,2 @@
FROM kdeneon/all
FROM kdeneon/all:user
RUN sudo apt-get update && sudo apt-get -y install build-essential cmake extra-cmake-modules gettext kio-dev libatasmart-dev libboost-python-dev libkf5config-dev libkf5coreaddons-dev libkf5i18n-dev libkf5iconthemes-dev libkf5parts-dev libkf5service-dev libkf5solid-dev libkpmcore-dev libparted-dev libpolkit-qt5-1-dev libqt5svg5-dev libqt5webkit5-dev libyaml-cpp-dev os-prober pkg-config python3-dev qtbase5-dev qtdeclarative5-dev qttools5-dev qttools5-dev-tools

View File

@@ -55,14 +55,7 @@ CalamaresApplication::CalamaresApplication( int& argc, char* argv[] )
QFont f = font();
cDebug() << "Default font ====="
<< "\nPixel size: " << f.pixelSize()
<< "\nPoint size: " << f.pointSize()
<< "\nPoint sizeF: " << f.pointSizeF()
<< "\nFont family: " << f.family()
<< "\nMetric height:" << QFontMetrics( f ).height();
// The following line blocks for 15s on Qt 5.1.0
cDebug() << "Font height:" << QFontMetrics( f ).height();
cDebug() << "Default font size" << f.pointSize() << ';' << f.pixelSize() << "px";
CalamaresUtils::setDefaultFontSize( f.pointSize() );
cDebug() << "Available languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' );

View File

@@ -1,7 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@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
@@ -30,6 +30,7 @@
#include <QApplication>
#include <QBoxLayout>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QLabel>
#include <QTreeView>
@@ -37,10 +38,8 @@
CalamaresWindow::CalamaresWindow( QWidget* parent )
: QWidget( parent )
, m_debugWindow( nullptr )
, m_viewManager( nullptr )
{
// Hide close button
setWindowFlags( Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint );
CALAMARES_RETRANSLATE(
setWindowTitle( tr( "%1 Installer" )
.arg( *Calamares::Branding::ProductName ) );
@@ -139,10 +138,10 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
CalamaresUtils::unmarginLayout( sideLayout );
CalamaresUtils::unmarginLayout( mainLayout );
Calamares::ViewManager* vm = Calamares::ViewManager::instance( this );
connect( vm, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
m_viewManager = Calamares::ViewManager::instance( this );
connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
mainLayout->addWidget( vm->centralWidget() );
mainLayout->addWidget( m_viewManager->centralWidget() );
}
void
@@ -156,3 +155,15 @@ CalamaresWindow::enlarge( QSize enlarge )
resize( w, h );
}
void
CalamaresWindow::closeEvent( QCloseEvent* event )
{
if ( ( !m_viewManager ) || m_viewManager->confirmCancelInstallation() )
{
event->accept();
qApp->quit();
}
else
event->ignore();
}

View File

@@ -1,7 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@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
@@ -26,6 +26,7 @@
namespace Calamares
{
class DebugWindow;
class ViewManager;
}
/**
@@ -46,8 +47,12 @@ public slots:
*/
void enlarge( QSize enlarge );
protected:
virtual void closeEvent( QCloseEvent* e ) override;
private:
QPointer< Calamares::DebugWindow > m_debugWindow;
QPointer< Calamares::DebugWindow > m_debugWindow; // Managed by self
Calamares::ViewManager* m_viewManager;
};
#endif //CALAMARESWINDOW_H

View File

@@ -1,7 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@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
@@ -88,30 +88,8 @@ ViewManager::ViewManager( QObject* parent )
connect( m_back, &QPushButton::clicked, this, &ViewManager::back );
m_back->setEnabled( false );
connect( m_quit, &QPushButton::clicked,
this, [this]()
{
// If it's NOT the last page of the last step, we ask for confirmation
if ( !( m_currentStep == m_steps.count() -1 &&
m_steps.last()->isAtEnd() ) )
{
QMessageBox mb( QMessageBox::Question,
tr( "Cancel installation?" ),
tr( "Do you really want to cancel the current install process?\n"
"The installer will quit and all changes will be lost." ),
QMessageBox::Yes | QMessageBox::No,
m_widget );
mb.setDefaultButton( QMessageBox::No );
mb.button( QMessageBox::Yes )->setText( tr( "&Yes" ) );
mb.button( QMessageBox::No )->setText( tr( "&No" ) );
int response = mb.exec();
if ( response == QMessageBox::Yes )
qApp->quit();
}
else // Means we're at the end, no need to confirm.
qApp->quit();
} );
connect( m_quit, &QPushButton::clicked, this,
[this]() { if ( this->confirmCancelInstallation() ) qApp->quit(); } );
connect( JobQueue::instance(), &JobQueue::failed,
this, &ViewManager::onInstallationFailed );
connect( JobQueue::instance(), &JobQueue::finished,
@@ -302,4 +280,26 @@ ViewManager::back()
}
}
bool ViewManager::confirmCancelInstallation()
{
// If it's NOT the last page of the last step, we ask for confirmation
if ( !( m_currentStep == m_steps.count() -1 &&
m_steps.last()->isAtEnd() ) )
{
QMessageBox mb( QMessageBox::Question,
tr( "Cancel installation?" ),
tr( "Do you really want to cancel the current install process?\n"
"The installer will quit and all changes will be lost." ),
QMessageBox::Yes | QMessageBox::No,
m_widget );
mb.setDefaultButton( QMessageBox::No );
mb.button( QMessageBox::Yes )->setText( tr( "&Yes" ) );
mb.button( QMessageBox::No )->setText( tr( "&No" ) );
int response = mb.exec();
return response == QMessageBox::Yes;
}
else // Means we're at the end, no need to confirm.
return true;
}
} // namespace

View File

@@ -1,7 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@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
@@ -86,6 +86,13 @@ public:
*/
int currentStepIndex() const;
/**
* @ brief Called when "Cancel" is clicked; asks for confirmation.
* Other means of closing Calamares also call this method, e.g. alt-F4.
* At the end of installation, no confirmation is asked. Returns true
* if the user confirms closing the window.
*/
bool confirmCancelInstallation();
public slots:
/**

View File

@@ -1,5 +1,11 @@
include( CMakeColors )
# The variable SKIP_MODULES can be set to skip particular modules;
# individual modules can also decide they must be skipped (e.g. OS-specific
# modules, or ones with unmet dependencies). Collect the skipped modules
# in this list.
set( LIST_SKIPPED_MODULES "" )
if( BUILD_TESTING )
add_executable( test_conf test_conf.cpp )
target_link_libraries( test_conf ${YAMLCPP_LIBRARY} )
@@ -13,11 +19,24 @@ foreach( SUBDIRECTORY ${SUBDIRECTORIES} )
if( NOT DO_SKIP EQUAL -1 )
message( "${ColorReset}-- Skipping module ${BoldRed}${SUBDIRECTORY}${ColorReset}." )
message( "" )
list( APPEND LIST_SKIPPED_MODULES "${SUBDIRECTORY} (user request)" )
elseif( ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" ) AND
( DO_SKIP EQUAL -1 ) )
set( SKIPPED_MODULES )
calamares_add_module_subdirectory( ${SUBDIRECTORY} )
if ( SKIPPED_MODULES )
list( APPEND LIST_SKIPPED_MODULES "${SKIPPED_MODULES}" )
endif()
endif()
endforeach()
if ( LIST_SKIPPED_MODULES )
message( "${ColorReset}-- Skipped modules:" )
foreach( SUBDIRECTORY ${LIST_SKIPPED_MODULES} )
message( "${ColorReset}-- Skipped ${BoldRed}${SUBDIRECTORY}${ColorReset}." )
endforeach()
message( "" )
endif()
include( CalamaresAddTranslations )
add_calamares_python_translations( ${CALAMARES_TRANSLATION_LANGUAGES} )

View File

@@ -1,9 +1,26 @@
find_package(ECM ${ECM_VERSION} NO_MODULE)
if( ECM_FOUND AND BUILD_TESTING )
include( ECMAddTests )
find_package( Qt5 COMPONENTS Core Test REQUIRED )
endif()
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
set( geoip_src GeoIP.cpp GeoIPFreeGeoIP.cpp )
set( geoip_libs )
find_package(Qt5 COMPONENTS Xml)
if( Qt5Xml_FOUND )
list( APPEND geoip_src GeoIPXML.cpp )
list( APPEND geoip_libs Qt5::Xml )
add_definitions( -DHAVE_XML )
endif()
calamares_add_plugin( locale
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
${geoip_src}
LCLocaleDialog.cpp
LocaleConfiguration.cpp
LocalePage.cpp
@@ -17,6 +34,28 @@ calamares_add_plugin( locale
LINK_PRIVATE_LIBRARIES
calamaresui
Qt5::Network
${geoip_libs}
${YAMLCPP_LIBRARY}
SHARED_LIB
)
if( ECM_FOUND AND BUILD_TESTING )
ecm_add_test(
GeoIPTests.cpp
${geoip_src}
TEST_NAME
geoiptest
LINK_LIBRARIES
calamaresui
Qt5::Network
Qt5::Test
${geoip_libs}
${YAMLCPP_LIBRARY}
)
set_target_properties( geoiptest PROPERTIES AUTOMOC TRUE )
endif()
if( BUILD_TESTING )
add_executable( test_geoip test_geoip.cpp ${geoip_src} )
target_link_libraries( test_geoip calamaresui Qt5::Network ${geoip_libs} ${YAMLCPP_LIBRARY} )
endif()

View File

@@ -0,0 +1,40 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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 "GeoIP.h"
#include "utils/Logger.h"
GeoIP::~GeoIP()
{
}
GeoIP::RegionZonePair
GeoIP::splitTZString( const QString& timezoneString )
{
QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts );
if ( tzParts.size() >= 2 )
{
cDebug() << "GeoIP reporting" << timezoneString;
QString region = tzParts.takeFirst();
QString zone = tzParts.join( '/' );
return qMakePair( region, zone );
}
return qMakePair( QString(), QString() );
}

View File

@@ -0,0 +1,56 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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 GEOIP_H
#define GEOIP_H
#include <QPair>
#include <QString>
#include <QUrl>
class QByteArray;
/**
* @brief Interface for GeoIP retrievers.
*
* A GeoIP retriever takes a configured URL (from the config file)
* and can handle the data returned from its interpretation of that
* configured URL, returning a region and zone.
*/
struct GeoIP
{
using RegionZonePair = QPair<QString, QString>;
virtual ~GeoIP();
/** @brief Handle a (successful) request by interpreting the data.
*
* Should return a ( <zone>, <region> ) pair, e.g.
* ( "Europe", "Amsterdam" ). This is called **only** if the
* request to the fullUrl was successful; the handler
* is free to read as much, or as little, data as it
* likes. On error, returns a RegionZonePair with empty
* strings (e.g. ( "", "" ) ).
*/
virtual RegionZonePair processReply( const QByteArray& ) = 0;
/** @brief Splits a region/zone string into a pair. */
static RegionZonePair splitTZString( const QString& s );
} ;
#endif

View File

@@ -0,0 +1,55 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2018, Adriaan de Groot <groot@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 "GeoIPFreeGeoIP.h"
#include "utils/Logger.h"
#include "utils/YamlUtils.h"
#include <QByteArray>
#include <yaml-cpp/yaml.h>
GeoIP::RegionZonePair
FreeGeoIP::processReply( const QByteArray& data )
{
try
{
YAML::Node doc = YAML::Load( data );
QVariant var = CalamaresUtils::yamlToVariant( doc );
if ( !var.isNull() &&
var.isValid() &&
var.type() == QVariant::Map )
{
QVariantMap map = var.toMap();
if ( map.contains( "time_zone" ) &&
!map.value( "time_zone" ).toString().isEmpty() )
{
return splitTZString( map.value( "time_zone" ).toString() );
}
}
}
catch ( YAML::Exception& e )
{
CalamaresUtils::explainYamlException( e, data, "GeoIP data");
}
return qMakePair( QString(), QString() );
}

View File

@@ -0,0 +1,37 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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 GEOIPFREEGEOIP_H
#define GEOIPFREEGEOIP_H
#include "GeoIP.h"
/** @brief GeoIP lookup via freegeoip.com
*
* This is the original implementation of GeoIP lookup,
* using the FreeGeoIP service, or similar which returns
* data in the same format.
*
* The data is assumed to be in JSON format with a time_zone attribute.
*/
struct FreeGeoIP : public GeoIP
{
virtual RegionZonePair processReply( const QByteArray& );
} ;
#endif

View File

@@ -0,0 +1,140 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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 "GeoIPTests.h"
#include "GeoIPFreeGeoIP.h"
#ifdef HAVE_XML
#include "GeoIPXML.h"
#endif
#include <QtTest/QtTest>
QTEST_GUILESS_MAIN( GeoIPTests )
GeoIPTests::GeoIPTests()
{
}
GeoIPTests::~GeoIPTests()
{
}
void
GeoIPTests::initTestCase()
{
}
void
GeoIPTests::testJSON()
{
static const char data[] =
"{\"time_zone\":\"Europe/Amsterdam\"}";
FreeGeoIP handler;
auto tz = handler.processReply( data );
QCOMPARE( tz.first, QLatin1String( "Europe" ) );
QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) );
// JSON is quite tolerant
tz = handler.processReply( "time_zone: \"Europe/Brussels\"" );
QCOMPARE( tz.second, QLatin1String( "Brussels" ) );
tz = handler.processReply( "time_zone: America/New_York\n" );
QCOMPARE( tz.first, QLatin1String( "America" ) );
}
void
GeoIPTests::testJSONbad()
{
static const char data[] = "time_zone: 1";
FreeGeoIP handler;
auto tz = handler.processReply( data );
tz = handler.processReply( data );
QCOMPARE( tz.first, QString() );
tz = handler.processReply( "" );
QCOMPARE( tz.first, QString() );
tz = handler.processReply( "<html><body>404 Forbidden</body></html>" );
QCOMPARE( tz.first, QString() );
}
void
GeoIPTests::testXML()
{
static const char data[] =
R"(<Response>
<Ip>85.150.1.1</Ip>
<Status>OK</Status>
<CountryCode>NL</CountryCode>
<CountryCode3>NLD</CountryCode3>
<CountryName>Netherlands</CountryName>
<RegionCode>None</RegionCode>
<RegionName>None</RegionName>
<City>None</City>
<ZipPostalCode/>
<Latitude>50.0</Latitude>
<Longitude>4.0</Longitude>
<AreaCode>0</AreaCode>
<TimeZone>Europe/Amsterdam</TimeZone>
</Response>)";
#ifdef HAVE_XML
XMLGeoIP handler;
auto tz = handler.processReply( data );
QCOMPARE( tz.first, QLatin1String( "Europe" ) );
QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) );
#endif
}
void
GeoIPTests::testXML2()
{
static const char data[] =
"<Response><TimeZone>America/North Dakota/Beulah</TimeZone></Response>";
#ifdef HAVE_XML
XMLGeoIP handler;
auto tz = handler.processReply( data );
QCOMPARE( tz.first, QLatin1String( "America" ) );
QCOMPARE( tz.second, QLatin1String( "North Dakota/Beulah" ) );
#endif
}
void
GeoIPTests::testXMLbad()
{
#ifdef HAVE_XML
XMLGeoIP handler;
auto tz = handler.processReply( "{time_zone: \"Europe/Paris\"}" );
QCOMPARE( tz.first, QString() );
tz = handler.processReply( "<Response></Response>" );
QCOMPARE( tz.first, QString() );
tz = handler.processReply( "fnord<html/>" );
QCOMPARE( tz.first, QString() );
#endif
}

View File

@@ -0,0 +1,40 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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 GEOIPTESTS_H
#define GEOIPTESTS_H
#include <QObject>
class GeoIPTests : public QObject
{
Q_OBJECT
public:
GeoIPTests();
~GeoIPTests() override;
private Q_SLOTS:
void initTestCase();
void testJSON();
void testJSONbad();
void testXML();
void testXML2();
void testXMLbad();
};
#endif

View File

@@ -0,0 +1,50 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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 "GeoIPXML.h"
#include "utils/Logger.h"
#include <QNetworkReply>
#include <QtXml/QDomDocument>
GeoIP::RegionZonePair
XMLGeoIP::processReply( const QByteArray& data )
{
QString domError;
int errorLine, errorColumn;
QDomDocument doc;
if ( doc.setContent( data, false, &domError, &errorLine, &errorColumn ) )
{
const auto tzElements = doc.elementsByTagName( "TimeZone" );
cDebug() << "GeoIP found" << tzElements.length() << "elements";
for ( int it = 0; it < tzElements.length(); ++it )
{
auto e = tzElements.at(it).toElement();
return splitTZString( e.text() );
}
}
else
{
cDebug() << "GeoIP XML data error:" << domError << "(line" << errorLine << errorColumn << ')';
}
return qMakePair( QString(), QString() );
}

View File

@@ -0,0 +1,36 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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 GEOIPXML_H
#define GEOIPXML_H
#include "GeoIP.h"
/** @brief GeoIP lookup with XML data
*
* The data is assumed to be in XML format with a
* <Response><TimeZone></TimeZone></Response>
* element, which contains the text (string) for the region/zone. This
* format is expected by, e.g. the Ubiquity installer.
*/
struct XMLGeoIP : public GeoIP
{
virtual RegionZonePair processReply( const QByteArray& );
} ;
#endif

View File

@@ -43,9 +43,11 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
const QStringList& availableLocales,
const QString& countryCode )
{
LocaleConfiguration lc = LocaleConfiguration();
LocaleConfiguration lc;
// Note that the documentation how this works is in packages.conf
QString language = languageLocale.split( '_' ).first();
lc.myLanguageLocaleBcp47 = QLocale(language).bcp47Name();
lc.myLanguageLocaleBcp47 = QLocale(language).bcp47Name().toLower();
QStringList linesForLanguage;
for ( const QString &line : availableLocales )
@@ -288,7 +290,7 @@ LocaleConfiguration::isEmpty() const
QMap< QString, QString >
LocaleConfiguration::toMap()
LocaleConfiguration::toMap() const
{
QMap< QString, QString > map;
@@ -324,3 +326,9 @@ LocaleConfiguration::toMap()
return map;
}
QString
LocaleConfiguration::toBcp47() const
{
return myLanguageLocaleBcp47;
}

View File

@@ -35,16 +35,21 @@ public:
bool isEmpty() const;
QMap< QString, QString > toMap() const;
// Note that the documentation how this works is in packages.conf
QString toBcp47() const;
// These become all uppercase in locale.conf, but we keep them lowercase here to
// avoid confusion with locale.h.
QString lang, lc_numeric, lc_time, lc_monetary, lc_paper, lc_name, lc_address,
lc_telephone, lc_measurement, lc_identification;
QString myLanguageLocaleBcp47;
QMap< QString, QString > toMap();
// If the user has explicitly selected language (from the dialog)
// or numbers format, set these to avoid implicit changes to them.
bool explicit_lang, explicit_lc;
private:
QString myLanguageLocaleBcp47;
};
#endif // LOCALECONFIGURATION_H

View File

@@ -489,8 +489,10 @@ LocalePage::updateGlobalStorage()
->insert( "locationRegion", location.region );
Calamares::JobQueue::instance()->globalStorage()
->insert( "locationZone", location.zone );
Calamares::JobQueue::instance()->globalStorage()
->insert( "locale", m_selectedLocaleConfiguration.myLanguageLocaleBcp47);
const QString bcp47 = m_selectedLocaleConfiguration.toBcp47();
Calamares::JobQueue::instance()->globalStorage()->insert( "locale", bcp47 );
cDebug() << "Updated locale globals, BCP47=" << bcp47;
// If we're in chroot mode (normal install mode), then we immediately set the
// timezone on the live system.

View File

@@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2018, Adriaan de Groot <groot.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
@@ -18,11 +19,17 @@
#include "LocaleViewStep.h"
#include "GeoIP.h"
#include "GeoIPFreeGeoIP.h"
#ifdef HAVE_XML
#include "GeoIPXML.h"
#endif
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "LocalePage.h"
#include "timezonewidget/localeglobal.h"
#include "widgets/WaitingWidget.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
@@ -110,54 +117,52 @@ LocaleViewStep::setUpPage()
void
LocaleViewStep::fetchGeoIpTimezone()
{
QString actualUrl( m_geoipUrl );
GeoIP *handler = nullptr;
if ( m_geoipStyle.isEmpty() || m_geoipStyle == "legacy" )
{
actualUrl.append( "/json/" );
handler = new FreeGeoIP;
}
else if ( m_geoipStyle == "json" )
{
handler = new FreeGeoIP;
}
#if defined(HAVE_XML)
else if ( m_geoipStyle == "xml" )
{
handler = new XMLGeoIP;
}
#endif
else
{
cDebug() << "WARNING: GeoIP Style" << m_geoipStyle << "is not recognized.";
setUpPage();
return;
}
cDebug() << "Fetching GeoIP data from" << actualUrl;
QNetworkAccessManager *manager = new QNetworkAccessManager( this );
connect( manager, &QNetworkAccessManager::finished,
[=]( QNetworkReply* reply )
{
if ( reply->error() == QNetworkReply::NoError )
{
QByteArray data = reply->readAll();
try
{
YAML::Node doc = YAML::Load( data );
QVariant var = CalamaresUtils::yamlToVariant( doc );
if ( !var.isNull() &&
var.isValid() &&
var.type() == QVariant::Map )
{
QVariantMap map = var.toMap();
if ( map.contains( "time_zone" ) &&
!map.value( "time_zone" ).toString().isEmpty() )
{
QString timezoneString = map.value( "time_zone" ).toString();
QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts );
if ( tzParts.size() >= 2 )
{
cDebug() << "GeoIP reporting" << timezoneString;
QString region = tzParts.takeFirst();
QString zone = tzParts.join( '/' );
m_startingTimezone = qMakePair( region, zone );
}
}
}
}
catch ( YAML::Exception& e )
{
CalamaresUtils::explainYamlException( e, data, "GeoIP data");
}
auto tz = handler->processReply( reply->readAll() );
if ( !tz.first.isEmpty() )
m_startingTimezone = tz;
else
cDebug() << "WARNING: GeoIP lookup at" << reply->url() << "failed.";
}
delete handler;
reply->deleteLater();
manager->deleteLater();
setUpPage();
} );
QNetworkRequest request;
QString requestUrl = QString( "%1/json" )
.arg( QUrl::fromUserInput( m_geoipUrl ).toString() );
request.setUrl( QUrl( requestUrl ) );
request.setUrl( QUrl::fromUserInput( actualUrl ) );
request.setAttribute( QNetworkRequest::FollowRedirectsAttribute, true );
manager->get( request );
}
@@ -293,4 +298,10 @@ LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
m_geoipUrl = configurationMap.value( "geoipUrl" ).toString();
}
if ( configurationMap.contains( "geoipStyle" ) &&
configurationMap.value( "geoipStyle" ).type() == QVariant::String &&
!configurationMap.value( "geoipStyle" ).toString().isEmpty() )
{
m_geoipStyle = configurationMap.value( "geoipStyle" ).toString();
}
}

View File

@@ -76,6 +76,7 @@ private:
QPair< QString, QString > m_startingTimezone;
QString m_localeGenPath;
QString m_geoipUrl;
QString m_geoipStyle;
QList< Calamares::job_ptr > m_jobs;
};

View File

@@ -1,7 +1,56 @@
---
# The starting timezone (e.g. the pin-on-the-map) when entering
# the locale page can be set through keys *region* and *zone*.
# If either is not set, defaults to America/New_York.
#
region: "America"
zone: "New_York"
# GeoIP settings. Leave commented out to disable GeoIP.
# Some distros come with a meaningfully commented and easy to parse
# `/etc/locale.gen`, and others ship a separate file
# `/usr/share/i18n/SUPPORTED` with a clean list of supported locales.
# We first try SUPPORTED, and if it doesn't exist, we fall back
# to parsing the lines from `locale.gen`. For distro's that ship
# the `locale.gen` file installed elsewhere, the key *localeGenPath*
# can be used to specify where it is. If not set, the default
# `/etc/locale.gen` is used.
#
#localeGenPath: "/etc/locale.gen"
# GeoIP settings. Leave commented out to disable GeoIP.
#
# An HTTP request is made to *geoipUrl* -- depending on the geoipStyle,
# the URL may be modified before use. The request should return
# valid data in a suitable format, depending on geoipStyle;
# generally this includes a string value with the timezone
# in <region>/<zone> format.
#
# Note that this example URL works, but the service is shutting
# down in June 2018.
#
# Suitable JSON data looks like
# ```
# {"time_zone":"America/New_York"}
# ```
# Suitable XML data looks like
# ```
# <Response><TimeZone>Europe/Brussels</TimeZone></Response>
# ```
#
#geoipUrl: "freegeoip.net"
# GeoIP style. Leave commented out for the "legacy" interpretation.
# This setting only makes sense if geoipUrl is set, enabliing geoIP.
#
# Possible values are:
# unset same as "legacy"
# blank same as "legacy"
# "legacy" appends "/json" to geoipUrl, above, and uses JSON format
# (which is what freegeoip.net provides there).
# "json" URL is not modified, uses JSON format.
# "xml" URL is not modified, uses XML format.
#
# The JSON format is provided by freegeoip.net, but that service is
# shutting down in June 2018. There are other providers with the same
# format. XML format is provided for Ubiquity.
#geoipStyle: "legacy"

View File

@@ -0,0 +1,73 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@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/>.
*/
/**
* This is a test-application that does one GeoIP parse.
*/
#include <iostream>
#include "GeoIPFreeGeoIP.h"
#ifdef HAVE_XML
#include "GeoIPXML.h"
#endif
using std::cerr;
int main(int argc, char** argv)
{
if (argc != 2)
{
cerr << "Usage: curl url | test_geoip <format>\n";
return 1;
}
GeoIP* handler = nullptr;
if ( QLatin1String( "json" ) == argv[1] )
handler = new FreeGeoIP;
#ifdef HAVE_XML
else if ( QLatin1String( "xml" ) == argv[1] )
handler = new XMLGeoIP;
#endif
if ( !handler )
{
cerr << "Unknown format '" << argv[1] << "'\n";
return 1;
}
QByteArray ba;
while( !std::cin.eof() ) {
char arr[1024];
std::cin.read(arr,sizeof(arr));
int s = std::cin.gcount();
ba.append(arr, s);
}
auto tz = handler->processReply( ba );
if ( tz.first.isEmpty() )
{
std::cout << "No TimeZone determined from input.\n";
}
else
{
std::cout << "TimeZone Region=" << tz.first.toLatin1().constData() << "\nTimeZone Zone=" << tz.second.toLatin1().constData() << '\n';
}
return 0;
}

View File

@@ -318,7 +318,10 @@ def subst_locale(plist):
"""
locale = libcalamares.globalstorage.value("locale")
if not locale:
return plist
# It is possible to skip the locale-setting entirely.
# Then pretend it is "en", so that {LOCALE}-decorated
# package names are removed from the list.
locale = "en"
ret = []
for packagedata in plist:
@@ -364,20 +367,20 @@ def run_operations(pkgman, entry):
global group_packages, completed_packages, mode_packages
for key in entry.keys():
entry[key] = subst_locale(entry[key])
group_packages = len(entry[key])
package_list = subst_locale(entry[key])
group_packages = len(package_list)
if key == "install":
_change_mode(INSTALL)
if all([isinstance(x, str) for x in entry[key]]):
pkgman.install(entry[key])
if all([isinstance(x, str) for x in package_list]):
pkgman.install(package_list)
else:
for package in entry[key]:
for package in package_list:
pkgman.install_package(package)
elif key == "try_install":
_change_mode(INSTALL)
# we make a separate package manager call for each package so a
# single failing package won't stop all of them
for package in entry[key]:
for package in package_list:
try:
pkgman.install_package(package)
except subprocess.CalledProcessError:
@@ -386,10 +389,10 @@ def run_operations(pkgman, entry):
libcalamares.utils.debug(warn_text)
elif key == "remove":
_change_mode(REMOVE)
pkgman.remove(entry[key])
pkgman.remove(package_list)
elif key == "try_remove":
_change_mode(REMOVE)
for package in entry[key]:
for package in package_list:
try:
pkgman.remove([package])
except subprocess.CalledProcessError:
@@ -398,9 +401,9 @@ def run_operations(pkgman, entry):
libcalamares.utils.debug(warn_text)
elif key == "localInstall":
_change_mode(INSTALL)
pkgman.install(entry[key], from_local=True)
pkgman.install(package_list, from_local=True)
completed_packages += len(entry[key])
completed_packages += len(package_list)
libcalamares.job.setprogress(completed_packages * 1.0 / total_packages)
libcalamares.utils.debug(pretty_name())
@@ -444,7 +447,7 @@ def run():
completed_packages = 0
for op in operations:
for packagelist in op.values():
total_packages += len(packagelist)
total_packages += len(subst_locale(packagelist))
if not total_packages:
# Avoids potential divide-by-zero in progress reporting

View File

@@ -76,7 +76,7 @@ update_db: true
# pre-script: touch /tmp/installing-vi
# post-script: rm -f /tmp/installing-vi
#
# The pre- and post-scripts are optional, but not both optional: using
# The pre- and post-scripts are optional, but you cannot leave both out: using
# "package: vi" with neither script option will trick Calamares into
# trying to install a package named "package: vi", which is unlikely to work.
#
@@ -84,11 +84,16 @@ update_db: true
# packages for software based on the selected system locale. By including
# the string LOCALE in the package name, the following happens:
#
# - if the system locale is English (generally US English; en_GB is a valid
# localization), then the package is not installed at all,
# - otherwise $LOCALE or ${LOCALE} is replaced by the Bcp47 name of the selected
# system locale, e.g. nl_BE. Note that just plain LOCALE will not be replaced,
# so foo-LOCALE will be unchanged, while foo-$LOCALE will be changed.
# - if the system locale is English (any variety), then the package is not
# installed at all,
# - otherwise $LOCALE or ${LOCALE} is replaced by the **lower-cased** BCP47
# name of the **language** part of the selected system locale (not the
# country/region/dialect part), e.g. selecting *nl_BE* will use *nl*
# here.
#
# Take care that just plain LOCALE will not be replaced, so foo-LOCALE will
# be left unchanged, while foo-$LOCALE will be changed. However, foo-LOCALE
# **will** be removed from the list of packages, if English is selected.
#
# The following installs localizations for vi, if they are relevant; if
# there is no localization, installation continues normally.
@@ -127,6 +132,7 @@ update_db: true
operations:
- install:
- vi
- vi-${LOCALE}
- wget
- binutils
- remove:

View File

@@ -1,22 +1,55 @@
find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
find_package( KF5 5.29 REQUIRED CoreAddons Plasma Package )
# Requires a sufficiently recent Plasma framework, but also
# needs a runtime support component (which we don't test for).
set( lnf_ver 5.41 )
calamares_add_plugin( plasmalnf
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
PlasmaLnfViewStep.cpp
PlasmaLnfPage.cpp
PlasmaLnfJob.cpp
ThemeWidget.cpp
RESOURCES
page_plasmalnf.qrc
UI
page_plasmalnf.ui
LINK_PRIVATE_LIBRARIES
calamaresui
KF5::Package
KF5::Plasma
SHARED_LIB
find_package( KF5Config ${lnf_ver} )
find_package( KF5Plasma ${lnf_ver} )
find_package( KF5Package ${lnf_ver} )
set_package_properties(
KF5Config PROPERTIES
PURPOSE "For finding default Plasma Look-and-Feel"
)
set_package_properties(
KF5Plasma PROPERTIES
PURPOSE "For Plasma Look-and-Feel selection"
)
set_package_properties(
KF5Package PROPERTIES
PURPOSE "For Plasma Look-and-Feel selection"
)
if ( KF5Plasma_FOUND AND KF5Package_FOUND )
if ( KF5Config_FOUND )
set( option_kf5 Config )
set( option_defs WITH_KCONFIG )
# set( option_libs KF5::Config ) # Not needed anyway
endif()
find_package( KF5 ${lnf_ver} REQUIRED CoreAddons Plasma Package ${option_kf5} )
calamares_add_plugin( plasmalnf
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
COMPILE_DEFINITIONS
${option_defs}
SOURCES
PlasmaLnfViewStep.cpp
PlasmaLnfPage.cpp
PlasmaLnfJob.cpp
ThemeWidget.cpp
RESOURCES
page_plasmalnf.qrc
UI
page_plasmalnf.ui
LINK_PRIVATE_LIBRARIES
calamaresui
${option_libs}
KF5::Package
KF5::Plasma
SHARED_LIB
)
else()
calamares_skip_module( "plasmalnf (missing requirements)" )
endif()

View File

@@ -23,6 +23,8 @@
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include <QAbstractButton>
#include <KPackage/Package>
#include <KPackage/PackageLoader>
@@ -55,13 +57,18 @@ static ThemeInfoList plasma_themes()
PlasmaLnfPage::PlasmaLnfPage( QWidget* parent )
: QWidget( parent )
, ui( new Ui::PlasmaLnfPage )
, m_showAll( false )
, m_buttonGroup( nullptr )
{
ui->setupUi( this );
CALAMARES_RETRANSLATE(
{
ui->retranslateUi( this );
ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop. You can also skip this step and configure the look-and-feel once the system is installed." ) );
ui->generalExplanation->setText( tr(
"Please choose a look-and-feel for the KDE Plasma Desktop. "
"You can also skip this step and configure the look-and-feel "
"once the system is installed. Clicking on a look-and-feel "
"selection will give you a live preview of that look-and-feel.") );
updateThemeNames();
fillUi();
}
@@ -75,10 +82,18 @@ PlasmaLnfPage::setLnfPath( const QString& path )
}
void
PlasmaLnfPage::setEnabledThemes(const ThemeInfoList& themes)
PlasmaLnfPage::setEnabledThemes(const ThemeInfoList& themes, bool showAll )
{
m_enabledThemes = themes;
if ( showAll )
{
auto plasmaThemes = plasma_themes();
for ( auto& installed_theme : plasmaThemes )
if ( !m_enabledThemes.findById( installed_theme.id ) )
m_enabledThemes.append( installed_theme );
}
updateThemeNames();
winnowThemes();
fillUi();
@@ -87,9 +102,18 @@ PlasmaLnfPage::setEnabledThemes(const ThemeInfoList& themes)
void
PlasmaLnfPage::setEnabledThemesAll()
{
setEnabledThemes( plasma_themes() );
// Don't need to set showAll=true, because we're already passing in
// the complete list of installed themes.
setEnabledThemes( plasma_themes(), false );
}
void
PlasmaLnfPage::setPreselect( const QString& id )
{
m_preselect = id;
if ( !m_enabledThemes.isEmpty() )
fillUi();
}
void PlasmaLnfPage::updateThemeNames()
{
@@ -162,6 +186,11 @@ void PlasmaLnfPage::fillUi()
{
theme.widget->updateThemeName( theme );
}
if ( theme.id == m_preselect )
{
const QSignalBlocker b( theme.widget->button() );
theme.widget->button()->setChecked( true );
}
++c;
}
}

View File

@@ -46,10 +46,17 @@ public:
explicit PlasmaLnfPage( QWidget* parent = nullptr );
void setLnfPath( const QString& path );
/** @brief enable only the listed themes. */
void setEnabledThemes( const ThemeInfoList& themes );
/** @brief enable only the listed themes.
*
* Shows the listed @p themes with full information (e.g. screenshot).
* If @p showAll is true, then also show all installed themes
* not explicitly listed (without a screenshot).
*/
void setEnabledThemes( const ThemeInfoList& themes, bool showAll );
/** @brief enable all installed plasma themes. */
void setEnabledThemesAll();
/** @brief set which theme is to be preselected. */
void setPreselect( const QString& id );
signals:
void plasmaThemeSelected( const QString& id );
@@ -64,6 +71,8 @@ private:
Ui::PlasmaLnfPage* ui;
QString m_lnfPath;
QString m_preselect;
bool m_showAll; // If true, don't winnow according to enabledThemes
ThemeInfoList m_enabledThemes;
QButtonGroup *m_buttonGroup;

View File

@@ -26,8 +26,25 @@
#include <QProcess>
#include <QVariantMap>
#ifdef WITH_KCONFIG
#include <KConfigGroup>
#include <KSharedConfig>
#endif
CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin<PlasmaLnfViewStep>(); )
static QString
currentPlasmaTheme()
{
#ifdef WITH_KCONFIG
KConfigGroup cg( KSharedConfig::openConfig( QStringLiteral( "kdeglobals" ) ), "KDE" );
return cg.readEntry( "LookAndFeelPackage", QString() );
#else
cWarning() << "No KConfig support, cannot determine Plasma theme.";
return QString();
#endif
}
PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new PlasmaLnfPage )
@@ -137,10 +154,22 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
liveUser = configurationMap.value( "liveuser" ).toString();
m_liveUser = liveUser;
QString preselect;
if ( configurationMap.contains( "preselect" ) && configurationMap.value( "preselect" ).type() == QVariant::String )
preselect = configurationMap.value( "preselect" ).toString();
if ( preselect == QStringLiteral( "*" ) )
preselect = currentPlasmaTheme();
if ( !preselect.isEmpty() )
m_widget->setPreselect( preselect );
bool showAll( false );
if ( configurationMap.contains( "showAll" ) && configurationMap.value( "showAll" ).type() == QVariant::Bool )
showAll = configurationMap.value( "showAll" ).toBool();
if ( configurationMap.contains( "themes" ) &&
configurationMap.value( "themes" ).type() == QVariant::List )
{
ThemeInfoList allThemes;
ThemeInfoList listedThemes;
auto themeList = configurationMap.value( "themes" ).toList();
// Create the ThemInfo objects for the listed themes; information
// about the themes from Plasma (e.g. human-readable name and description)
@@ -149,14 +178,14 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
if ( i.type() == QVariant::Map )
{
auto iv = i.toMap();
allThemes.append( ThemeInfo( iv.value( "theme" ).toString(), iv.value( "image" ).toString() ) );
listedThemes.append( ThemeInfo( iv.value( "theme" ).toString(), iv.value( "image" ).toString() ) );
}
else if ( i.type() == QVariant::String )
allThemes.append( ThemeInfo( i.toString() ) );
listedThemes.append( ThemeInfo( i.toString() ) );
if ( allThemes.length() == 1 )
if ( listedThemes.length() == 1 )
cDebug() << "WARNING: only one theme enabled in plasmalnf";
m_widget->setEnabledThemes( allThemes );
m_widget->setEnabledThemes( listedThemes, showAll );
}
else
m_widget->setEnabledThemesAll(); // All of them

View File

@@ -61,9 +61,9 @@ public slots:
private:
PlasmaLnfPage* m_widget;
QString m_lnfPath;
QString m_themeId;
QString m_liveUser;
QString m_lnfPath; // Path to the lnf tool
QString m_themeId; // Id of selected theme
QString m_liveUser; // Name of the live user (for OEM mode)
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( PlasmaLnfViewStepFactory )

View File

@@ -62,7 +62,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent)
layout->addWidget( image_label, 1 );
layout->addWidget( m_description, 3 );
connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked );
connect( m_check, &QRadioButton::toggled, this, &ThemeWidget::clicked );
}
void

View File

@@ -13,8 +13,9 @@ lnftool: "/usr/bin/lookandfeeltool"
# You can limit the list of Plasma look-and-feel themes by listing ids
# here. If this key is not present, all of the installed themes are listed.
# If the key is present, only installed themes that are *also* included
# in the list are shown (could be none!).
# If the key is present, only installed themes that are **also** included
# in the list are shown (could be none!). See the *showAll* key, below,
# to change that.
#
# Themes may be listed by id, (e.g. fluffy-bunny, below) or as a theme
# and an image (e.g. breeze) which will be used to show a screenshot.
@@ -27,3 +28,26 @@ themes:
- theme: org.kde.breezedark.desktop
image: "breeze-dark.png"
- org.kde.fluffy-bunny.desktop
# If *showAll* is true, then all installed themes are shown in the
# UI for selection, even if they are not listed in *themes*. This
# allows selection of all themes even while not all of them are
# listed in *themes* -- which is useful to show screenshots for those
# you do have a screenshot for.
showAll: false
# You can pre-select one of the themes; it is not applied
# immediately, but its radio-button is switched on to indicate
# that that is the theme (that is most likely) currently in use.
# Do this only on Live images where you are reasonably sure
# that the user is not going to change the theme out from under
# themselves before running the installer.
#
# If this key is present, its value should be the id of the theme
# which should be pre-selected. If absent, empty, or the pre-selected
# theme is not found on the live system, no theme will be pre-selected.
#
# As a special setting, use "*", to try to find the currently-
# selected theme by reading the Plasma configuration. This requires
# KF5::Config at build- and run-time.
preselect: "*"

View File

@@ -25,6 +25,6 @@ requirements:
# If any of these conditions are not met, the user cannot
# continue past the welcome page.
required:
- storage
# - storage
- ram
- root
# - root