diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..1dd301d99 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,29 @@ +#### Submission type + + - [ ] Bug report + - [ ] Feature Request + + +#### Info regarding which version of Calamares is used, which Distribution + +> … + +#### Provide information on how the disks are set up, in detail, with full logs of commands issued + +> … + +#### What do you expect to have happen when Calamares installs? + +> … + +#### Describe the issue you encountered + +> … + +#### Steps to reproduce the problem + +> … + +#### Include the installation.log: + +> … diff --git a/.travis.yml b/.travis.yml index ec6678a36..0b18d927d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,7 @@ notifications: install: - docker build -t calamares . - - pip install pycodestyle script: - docker run -v $PWD:/src --tmpfs /build:rw,size=65536k calamares bash -lc "cd /build && cmake -DWEBVIEW_FORCE_WEBKIT=1 -DKDE_INSTALL_USE_QT_SYS_PATHS=ON /src && make -j2 && make install DESTDIR=/build/INSTALL_ROOT" - - pycodestyle --exclude=thirdparty,.git $PWD diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e8d97d25..5978a1c53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) set( CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG" ) set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g" ) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-undefined-reinterpret-cast -Wno-global-constructors -Wno-exit-time-destructors" ) set( CMAKE_CXX_FLAGS_DEBUG "-g" ) set( CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" ) set( CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG" ) diff --git a/src/calamares/progresstree/ViewStepItem.cpp b/src/calamares/progresstree/ViewStepItem.cpp index d2fff08ca..b54fa07eb 100644 --- a/src/calamares/progresstree/ViewStepItem.cpp +++ b/src/calamares/progresstree/ViewStepItem.cpp @@ -46,6 +46,7 @@ void ViewStepItem::appendChild( ProgressTreeItem* item ) { Q_ASSERT( false ); + Q_UNUSED( item ); } diff --git a/src/crashreporter/main.cpp b/src/crashreporter/main.cpp index 17e6fd13b..8d7ef16e0 100644 --- a/src/crashreporter/main.cpp +++ b/src/crashreporter/main.cpp @@ -41,11 +41,11 @@ #ifdef Q_OS_LINUX -const char* k_usage = +static const char k_usage[] = "Usage:\n" " CrashReporter \n"; #else -const char* k_usage = +static const char k_usage[] = "Usage:\n" " CrashReporter \n"; #endif diff --git a/src/libcalamares/CppJob.cpp b/src/libcalamares/CppJob.cpp index 1925e398b..73868799a 100644 --- a/src/libcalamares/CppJob.cpp +++ b/src/libcalamares/CppJob.cpp @@ -40,6 +40,8 @@ CppJob::setModuleInstanceKey( const QString& instanceKey ) void CppJob::setConfigurationMap( const QVariantMap& configurationMap ) -{} +{ + Q_UNUSED( configurationMap ); +} } diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 5c18c2d29..7caf2a18c 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -39,9 +39,9 @@ using namespace std; -ofstream logfile; -static int s_threshold = -1; -QMutex s_mutex; +static ofstream logfile; +static unsigned int s_threshold = 0; +static QMutex s_mutex; namespace Logger { @@ -49,20 +49,22 @@ namespace Logger static void log( const char* msg, unsigned int debugLevel, bool toDisk = true ) { - if ( s_threshold < 0 ) + if ( !s_threshold ) { if ( qApp->arguments().contains( "--debug" ) || qApp->arguments().contains( "-d" ) ) s_threshold = LOGVERBOSE; else - #ifdef QT_NO_DEBUG +#ifdef QT_NO_DEBUG s_threshold = RELEASE_LEVEL_THRESHOLD; - #else +#else s_threshold = DEBUG_LEVEL_THRESHOLD; - #endif +#endif + // Comparison is < threshold, below + ++s_threshold; } - if ( toDisk || (int)debugLevel <= s_threshold ) + if ( toDisk || debugLevel < s_threshold ) { QMutexLocker lock( &s_mutex ); @@ -78,7 +80,7 @@ log( const char* msg, unsigned int debugLevel, bool toDisk = true ) logfile.flush(); } - if ( debugLevel <= LOGEXTRA || (int)debugLevel <= s_threshold ) + if ( debugLevel <= LOGEXTRA || debugLevel < s_threshold ) { QMutexLocker lock( &s_mutex ); @@ -96,6 +98,8 @@ CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QS { static QMutex s_mutex; + Q_UNUSED( context ); + QByteArray ba = msg.toUtf8(); const char* message = ba.constData(); @@ -106,14 +110,12 @@ CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QS log( message, LOGVERBOSE ); break; + case QtInfoMsg: + log( message, 1 ); + break; + case QtCriticalMsg: - log( message, 0 ); - break; - case QtWarningMsg: - log( message, 0 ); - break; - case QtFatalMsg: log( message, 0 ); break; diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 72bed2000..0cf4b4ad3 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -52,7 +52,7 @@ namespace Logger virtual ~CDebug(); }; - DLLEXPORT void CalamaresLogHandler( QtMsgType type, const char* msg ); + DLLEXPORT void CalamaresLogHandler( QtMsgType type, const QMessageLogContext& context, const QString& msg ); DLLEXPORT void setupLogfile(); DLLEXPORT QString logFile(); } diff --git a/src/libcalamares/utils/Units.h b/src/libcalamares/utils/Units.h new file mode 100644 index 000000000..391d67194 --- /dev/null +++ b/src/libcalamares/utils/Units.h @@ -0,0 +1,65 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * 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 . + */ + +#ifndef LIBCALAMARES_UTILS_UNITS_H +#define LIBCALAMARES_UTILS_UNITS_H + +#include + +namespace CalamaresUtils +{ + +/** User defined literals, 1_MiB is 1 MibiByte (= 2^20 bytes) */ +constexpr qint64 operator ""_MiB( unsigned long long m ) +{ + return qint64(m) * 1024 * 1024; +} + +/** User defined literals, 1_GiB is 1 GibiByte (= 2^30 bytes) */ +constexpr qint64 operator ""_GiB( unsigned long long m ) +{ + return operator ""_MiB(m) * 1024; +} + +constexpr qint64 MiBtoBytes( unsigned long long m ) +{ + return operator ""_MiB( m ); +} + +constexpr qint64 GiBtoBytes( unsigned long long m ) +{ + return operator ""_GiB( m ); +} + +constexpr qint64 MiBToBytes( double m ) +{ + return qint64(m * 1024 * 1024); +} + +constexpr qint64 GiBtoBytes( double m ) +{ + return qint64(m * 1024 * 1024 * 1024); +} + +constexpr int BytesToMiB( qint64 b ) +{ + return int( b / 1024 / 1024 ); +} + +} // namespace +#endif diff --git a/src/libcalamaresui/ExecutionViewStep.cpp b/src/libcalamaresui/ExecutionViewStep.cpp index fb43122b9..37c2318d0 100644 --- a/src/libcalamaresui/ExecutionViewStep.cpp +++ b/src/libcalamaresui/ExecutionViewStep.cpp @@ -165,7 +165,7 @@ ExecutionViewStep::appendJobModuleInstanceKey( const QString& instanceKey ) void ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message ) { - m_progressBar->setValue( percent * m_progressBar->maximum() ); + m_progressBar->setValue( int( percent * m_progressBar->maximum() ) ); m_label->setText( message ); } diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index 7c331351d..5f756938f 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -100,9 +100,9 @@ public: /** * @brief instanceKey returns the instance key of this module. * @return a string with the instance key. - * A module instance's instance key is modulename@instanceid. - * @example "partition@partition" (default configuration) or - * "locale@someconfig" (custom configuration) + * A module instance's instance key is modulename\@instanceid. + * For instance, "partition\@partition" (default configuration) or + * "locale\@someconfig" (custom configuration) */ virtual QString instanceKey() const final; diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index d08cdf8dd..44eed30f0 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -219,14 +219,14 @@ ModuleManager::loadModules() } auto findCustomInstance = - [ customInstances ]( const QString& moduleName, - const QString& instanceId ) -> int + [ customInstances ]( const QString& module, + const QString& id) -> int { for ( int i = 0; i < customInstances.count(); ++i ) { auto thisInstance = customInstances[ i ]; - if ( thisInstance.value( "module" ) == moduleName && - thisInstance.value( "id" ) == instanceId ) + if ( thisInstance.value( "module" ) == module && + thisInstance.value( "id" ) == id ) return i; } return -1; diff --git a/src/libcalamaresui/utils/ImageRegistry.cpp b/src/libcalamaresui/utils/ImageRegistry.cpp index ad3e606ab..5e55b2293 100644 --- a/src/libcalamaresui/utils/ImageRegistry.cpp +++ b/src/libcalamaresui/utils/ImageRegistry.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Originally from Tomahawk, * Copyright 2012, Christian Muehlhaeuser @@ -52,14 +53,14 @@ ImageRegistry::icon( const QString& image, CalamaresUtils::ImageMode mode ) qint64 -ImageRegistry::cacheKey( const QSize& size, float opacity, QColor tint ) +ImageRegistry::cacheKey( const QSize& size, qreal opacity, QColor tint ) { - return size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) + tint.value(); + return size.width() * 100 + size.height() * 10 + int( opacity * 100.0 ) + tint.value(); } QPixmap -ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, float opacity, QColor tint ) +ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, qreal opacity, QColor tint ) { QHash< qint64, QPixmap > subsubcache; QHash< int, QHash< qint64, QPixmap > > subcache; @@ -135,7 +136,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils:: void -ImageRegistry::putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint ) +ImageRegistry::putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, qreal opacity, const QPixmap& pixmap, QColor tint ) { // cDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to image cache:" << image << size << mode; diff --git a/src/libcalamaresui/utils/ImageRegistry.h b/src/libcalamaresui/utils/ImageRegistry.h index 41ed2d6ac..4909b0183 100644 --- a/src/libcalamaresui/utils/ImageRegistry.h +++ b/src/libcalamaresui/utils/ImageRegistry.h @@ -35,11 +35,11 @@ public: explicit ImageRegistry(); QIcon icon( const QString& image, CalamaresUtils::ImageMode mode = CalamaresUtils::Original ); - QPixmap pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode = CalamaresUtils::Original, float opacity = 1.0, QColor tint = QColor( 0, 0, 0, 0 ) ); + QPixmap pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode = CalamaresUtils::Original, qreal opacity = 1.0, QColor tint = QColor( 0, 0, 0, 0 ) ); private: - qint64 cacheKey( const QSize& size, float opacity, QColor tint ); - void putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint ); + qint64 cacheKey( const QSize& size, qreal opacity, QColor tint ); + void putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, qreal opacity, const QPixmap& pixmap, QColor tint ); static ImageRegistry* s_instance; }; diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index 8bcde4b50..3287dc711 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -37,6 +37,18 @@ #include #include +class LayoutItem : public QListWidgetItem +{ +public: + QString data; + + virtual ~LayoutItem(); +}; + +LayoutItem::~LayoutItem() +{ +} + static QPersistentModelIndex findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout ) { @@ -54,7 +66,7 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout ) } KeyboardPage::KeyboardPage( QWidget* parent ) - : QWidget() + : QWidget( parent ) , ui( new Ui::Page_Keyboard ) , m_keyboardPreview( new KeyBoardPreview( this ) ) , m_defaultIndex( 0 ) @@ -369,6 +381,8 @@ static inline QStringList xkbmap_args( QStringList&& r, const QString& layout, c void KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous ) { + Q_UNUSED( previous ); + QPersistentModelIndex layoutIndex = ui->listLayout->currentIndex(); LayoutItem* variantItem = dynamic_cast< LayoutItem* >( current ); diff --git a/src/modules/keyboard/KeyboardPage.h b/src/modules/keyboard/KeyboardPage.h index 6f828f446..7dc92e035 100644 --- a/src/modules/keyboard/KeyboardPage.h +++ b/src/modules/keyboard/KeyboardPage.h @@ -64,15 +64,9 @@ protected slots: QListWidgetItem* previous ); private: - class LayoutItem : public QListWidgetItem - { - public: - QString data; - KeyboardGlobal::KeyboardInfo info; - }; - /// Guess a layout based on the split-apart locale void guessLayout( const QStringList& langParts ); + void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() ); diff --git a/src/modules/keyboard/KeyboardViewStep.cpp b/src/modules/keyboard/KeyboardViewStep.cpp index cdb2657dc..0dd326a8d 100644 --- a/src/modules/keyboard/KeyboardViewStep.cpp +++ b/src/modules/keyboard/KeyboardViewStep.cpp @@ -134,9 +134,6 @@ KeyboardViewStep::onLeave() void KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - // Save the settings to the global settings for the SetKeyboardLayoutJob to use - Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - if ( configurationMap.contains( "xOrgConfFileName" ) && configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String && !configurationMap.value( "xOrgConfFileName" ).toString().isEmpty() ) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 4882b1684..2172586ff 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -282,7 +282,7 @@ LocalePage::init( const QString& initialRegion, } else { - m_tzWidget->setCurrentLocation( "Europe", "Berlin" ); + m_tzWidget->setCurrentLocation( "America", "New_York" ); } emit m_tzWidget->locationChanged( m_tzWidget->getCurrentLocation() ); diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index 8f38e7f14..4b4219751 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -132,12 +132,12 @@ LocaleViewStep::fetchGeoIpTimezone() !map.value( "time_zone" ).toString().isEmpty() ) { QString timezoneString = map.value( "time_zone" ).toString(); - QStringList timezone = timezoneString.split( '/', QString::SkipEmptyParts ); - if ( timezone.size() >= 2 ) + QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts ); + if ( tzParts.size() >= 2 ) { cDebug() << "GeoIP reporting" << timezoneString; - QString region = timezone.takeFirst(); - QString zone = timezone.join( '/' ); + QString region = tzParts.takeFirst(); + QString zone = tzParts.join( '/' ); m_startingTimezone = qMakePair( region, zone ); } } @@ -271,8 +271,8 @@ LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } else { - m_startingTimezone = qMakePair( QStringLiteral( "Europe" ), - QStringLiteral( "Berlin" ) ); + m_startingTimezone = qMakePair( QStringLiteral( "America" ), + QStringLiteral( "New_York" ) ); } if ( configurationMap.contains( "localeGenPath" ) && diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 14e7bf010..9567661b2 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -25,6 +25,7 @@ #include "core/PartUtils.h" #include "utils/CalamaresUtilsSystem.h" +#include "utils/Units.h" #include "JobQueue.h" #include "utils/Logger.h" #include "GlobalStorage.h" @@ -36,25 +37,10 @@ namespace PartitionActions { -constexpr qint64 operator ""_MiB( unsigned long long m ) -{ - return m * static_cast< qint64 >( 1024 ) * 1024; -} - -constexpr qint64 operator ""_GiB( unsigned long long m ) -{ - return operator ""_MiB(m) * static_cast< qint64 >( 1024 ); -} - -constexpr qint64 toMiB( unsigned long long m ) -{ - return operator ""_MiB( m ); -} - -constexpr qint64 toGiB( unsigned long long m ) -{ - return operator ""_GiB( m ); -} +using CalamaresUtils::GiBtoBytes; +using CalamaresUtils::MiBtoBytes; +using CalamaresUtils::operator""_GiB; +using CalamaresUtils::operator""_MiB; qint64 swapSuggestion( const qint64 availableSpaceB ) @@ -140,11 +126,11 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass empty_space_size = 1; } - qint64 firstFreeSector = toMiB(empty_space_size) / dev->logicalSize() + 1; + qint64 firstFreeSector = MiBtoBytes(empty_space_size) / dev->logicalSize() + 1; if ( isEfi ) { - qint64 lastSector = firstFreeSector + ( toMiB(uefisys_part_size) / dev->logicalSize() ); + qint64 lastSector = firstFreeSector + ( MiBtoBytes(uefisys_part_size) / dev->logicalSize() ); core->createPartitionTable( dev, PartitionTable::gpt ); Partition* efiPartition = KPMHelpers::createNewPartition( dev->partitionTable(), @@ -175,7 +161,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass qint64 availableSpaceB = ( dev->totalLogical() - firstFreeSector ) * dev->logicalSize(); suggestedSwapSizeB = swapSuggestion( availableSpaceB ); qint64 requiredSpaceB = - toGiB( gs->value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) + + GiBtoBytes( gs->value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) + suggestedSwapSizeB; // If there is enough room for ESP + root + swap, create swap, otherwise don't. diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index fcbfdb5fc..b4e9b0c9f 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -474,8 +474,7 @@ ChoicePage::doAlongsideSetupSplitter( const QModelIndex& current, part->partitionPath(), qRound64( part->used() * 1.1 ), part->capacity() - requiredStorageB, - part->capacity() / 2, - *Calamares::Branding::ProductName ); + part->capacity() / 2 ); if ( m_isEfi ) setupEfiSystemPartitionSelector(); diff --git a/src/modules/partition/gui/PartitionLabelsView.cpp b/src/modules/partition/gui/PartitionLabelsView.cpp index d7364fb5f..c0b7fdd41 100644 --- a/src/modules/partition/gui/PartitionLabelsView.cpp +++ b/src/modules/partition/gui/PartitionLabelsView.cpp @@ -43,7 +43,7 @@ static const int LABELS_MARGIN = LABEL_PARTITION_SQUARE_MARGIN; static const int CORNER_RADIUS = 2; -QStringList +static QStringList buildUnknownDisklabelTexts( Device* dev ) { QStringList texts = { QObject::tr( "Unpartitioned space or unknown partition table" ), @@ -54,7 +54,7 @@ buildUnknownDisklabelTexts( Device* dev ) PartitionLabelsView::PartitionLabelsView( QWidget* parent ) : QAbstractItemView( parent ) - , canBeSelected( []( const QModelIndex& ) { return true; } ) + , m_canBeSelected( []( const QModelIndex& ) { return true; } ) , m_extendedPartitionHidden( false ) { setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); @@ -100,6 +100,8 @@ PartitionLabelsView::sizeHint() const void PartitionLabelsView::paintEvent( QPaintEvent* event ) { + Q_UNUSED( event ); + QPainter painter( viewport() ); painter.fillRect( rect(), palette().window() ); painter.setRenderHint( QPainter::Antialiasing ); @@ -292,7 +294,6 @@ PartitionLabelsView::drawLabels( QPainter* painter, !modl->device()->partitionTable() ) // No disklabel or unknown { QStringList texts = buildUnknownDisklabelTexts( modl->device() ); - QSize labelSize = sizeForLabel( texts ); QColor labelColor = ColorUtils::unknownDisklabelColor(); drawLabel( painter, texts, labelColor, QPoint( rect.x(), rect.y() ), false /*can't be selected*/ ); } @@ -467,6 +468,8 @@ PartitionLabelsView::visualRect( const QModelIndex& idx ) const QRegion PartitionLabelsView::visualRegionForSelection( const QItemSelection& selection ) const { + Q_UNUSED( selection ); + return QRegion(); } @@ -516,7 +519,7 @@ PartitionLabelsView::setSelectionModel( QItemSelectionModel* selectionModel ) void PartitionLabelsView::setSelectionFilter( SelectionFilter canBeSelected ) { - this->canBeSelected = canBeSelected; + m_canBeSelected = canBeSelected; } @@ -530,6 +533,9 @@ PartitionLabelsView::setExtendedPartitionHidden( bool hidden ) QModelIndex PartitionLabelsView::moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) { + Q_UNUSED( cursorAction ); + Q_UNUSED( modifiers ); + return QModelIndex(); } @@ -537,6 +543,8 @@ PartitionLabelsView::moveCursor( CursorAction cursorAction, Qt::KeyboardModifier bool PartitionLabelsView::isIndexHidden( const QModelIndex& index ) const { + Q_UNUSED( index ); + return false; } @@ -545,7 +553,7 @@ void PartitionLabelsView::setSelection( const QRect& rect, QItemSelectionModel::SelectionFlags flags ) { QModelIndex eventIndex = indexAt( rect.topLeft() ); - if ( canBeSelected( eventIndex ) ) + if ( m_canBeSelected( eventIndex ) ) selectionModel()->select( eventIndex, flags ); } @@ -567,7 +575,7 @@ PartitionLabelsView::mouseMoveEvent( QMouseEvent* event ) if ( oldHoveredIndex != m_hoveredIndex ) { - if ( m_hoveredIndex.isValid() && !canBeSelected( m_hoveredIndex ) ) + if ( m_hoveredIndex.isValid() && !m_canBeSelected( m_hoveredIndex ) ) QGuiApplication::setOverrideCursor( Qt::ForbiddenCursor ); else QGuiApplication::restoreOverrideCursor(); @@ -580,6 +588,8 @@ PartitionLabelsView::mouseMoveEvent( QMouseEvent* event ) void PartitionLabelsView::leaveEvent( QEvent* event ) { + Q_UNUSED( event ); + QGuiApplication::restoreOverrideCursor(); if ( m_hoveredIndex.isValid() ) { @@ -593,7 +603,7 @@ void PartitionLabelsView::mousePressEvent( QMouseEvent* event ) { QModelIndex candidateIndex = indexAt( event->pos() ); - if ( canBeSelected( candidateIndex ) ) + if ( m_canBeSelected( candidateIndex ) ) QAbstractItemView::mousePressEvent( event ); else event->accept(); diff --git a/src/modules/partition/gui/PartitionLabelsView.h b/src/modules/partition/gui/PartitionLabelsView.h index fef453d44..c5646a417 100644 --- a/src/modules/partition/gui/PartitionLabelsView.h +++ b/src/modules/partition/gui/PartitionLabelsView.h @@ -83,7 +83,7 @@ private: QModelIndexList getIndexesToDraw( const QModelIndex& parent ) const; QStringList buildTexts( const QModelIndex& index ) const; - SelectionFilter canBeSelected; + SelectionFilter m_canBeSelected; bool m_extendedPartitionHidden; QString m_customNewRootLabel; diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 5d541c4e2..62e7a97a1 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -56,8 +56,8 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent ) : QWidget( parent ) , m_ui( new Ui_PartitionPage ) - , m_lastSelectedBootLoaderIndex(-1) , m_core( core ) + , m_lastSelectedBootLoaderIndex(-1) , m_isEfi( false ) { m_isEfi = PartUtils::isEfiSystem(); @@ -373,7 +373,7 @@ PartitionPage::updateFromCurrentDevice() // Establish connection here because selection model is destroyed when // model changes connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentChanged, - [ this ]( const QModelIndex& index, const QModelIndex& oldIndex ) + [ this ]( const QModelIndex&, const QModelIndex& ) { updateButtons(); } ); diff --git a/src/modules/partition/gui/PartitionSizeController.cpp b/src/modules/partition/gui/PartitionSizeController.cpp index d01924e8b..3cf915c7d 100644 --- a/src/modules/partition/gui/PartitionSizeController.cpp +++ b/src/modules/partition/gui/PartitionSizeController.cpp @@ -22,6 +22,8 @@ #include "core/ColorUtils.h" #include "core/KPMHelpers.h" +#include "utils/Units.h" + // Qt #include @@ -185,7 +187,7 @@ PartitionSizeController::doUpdateSpinBox() { if ( !m_spinBox ) return; - qint64 mbSize = m_partition->length() * m_device->logicalSize() / 1024 / 1024; + int mbSize = CalamaresUtils::BytesToMiB( m_partition->length() * m_device->logicalSize() ); m_spinBox->setValue( mbSize ); if ( m_currentSpinBoxValue != -1 && //if it's not the first time we're setting it m_currentSpinBoxValue != mbSize ) //and the operation changes the SB value diff --git a/src/modules/partition/gui/PartitionSplitterWidget.cpp b/src/modules/partition/gui/PartitionSplitterWidget.cpp index a4aacbe9f..4b0776344 100644 --- a/src/modules/partition/gui/PartitionSplitterWidget.cpp +++ b/src/modules/partition/gui/PartitionSplitterWidget.cpp @@ -34,18 +34,18 @@ #include static const int VIEW_HEIGHT = qMax( CalamaresUtils::defaultFontHeight() + 8, // wins out with big fonts - (int)( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts + int( CalamaresUtils::defaultFontHeight() * 0.6 ) + 22 ); // wins out with small fonts static const int CORNER_RADIUS = 3; static const int EXTENDED_PARTITION_MARGIN = qMax( 4, VIEW_HEIGHT / 6 ); PartitionSplitterWidget::PartitionSplitterWidget( QWidget* parent ) : QWidget( parent ) - , m_resizing( false ) , m_itemToResize( PartitionSplitterItem::null() ) , m_itemToResizeNext( PartitionSplitterItem::null() ) , m_itemMinSize( 0 ) , m_itemMaxSize( 0 ) , m_itemPrefSize( 0 ) + , m_resizing( false ) , m_resizeHandleX( 0 ) , HANDLE_SNAP( QApplication::startDragDistance() ) , m_drawNestedPartitions( false ) @@ -114,8 +114,7 @@ void PartitionSplitterWidget::setSplitPartition( const QString& path, qint64 minSize, qint64 maxSize, - qint64 preferredSize, - const QString& newLabel ) + qint64 preferredSize ) { cDebug() << Q_FUNC_INFO << "path:" << path << "\nminSize:" << minSize @@ -287,6 +286,8 @@ PartitionSplitterWidget::minimumSizeHint() const void PartitionSplitterWidget::paintEvent( QPaintEvent* event ) { + Q_UNUSED( event ); + QPainter painter( this ); painter.fillRect( rect(), palette().window() ); painter.setRenderHint( QPainter::Antialiasing ); @@ -400,6 +401,8 @@ PartitionSplitterWidget::mouseMoveEvent( QMouseEvent* event ) void PartitionSplitterWidget::mouseReleaseEvent( QMouseEvent* event ) { + Q_UNUSED( event ); + m_resizing = false; } @@ -491,7 +494,7 @@ PartitionSplitterWidget::drawResizeHandle( QPainter* painter, painter->setRenderHint( QPainter::Antialiasing, false ); painter->setPen( Qt::black ); - painter->drawLine( x, 0, x, h - 1 ); + painter->drawLine( x, 0, x, int(h) - 1 ); } @@ -511,20 +514,20 @@ PartitionSplitterWidget::drawPartitions( QPainter* painter, for ( int row = 0; row < count; ++row ) { const PartitionSplitterItem& item = items[ row ]; - int width; + qreal width; if ( row < count - 1 ) width = totalWidth * ( item.size / total ); else // Make sure we fill the last pixel column width = rect.right() - x + 1; - drawSection( painter, rect, x, width, item ); + drawSection( painter, rect, x, int(width), item ); if ( !item.children.isEmpty() ) { QRect subRect( x + EXTENDED_PARTITION_MARGIN, rect.y() + EXTENDED_PARTITION_MARGIN, - width - 2 * EXTENDED_PARTITION_MARGIN, + int(width) - 2 * EXTENDED_PARTITION_MARGIN, rect.height() - 2 * EXTENDED_PARTITION_MARGIN ); drawPartitions( painter, subRect, item.children ); @@ -600,7 +603,7 @@ PartitionSplitterWidget::computeItemsVector( const QVector< PartitionSplitterIte PartitionSplitterItem thisItem = originalItems[ row ]; QPair< QVector< PartitionSplitterItem >, qreal > pair = computeItemsVector( thisItem.children ); thisItem.children = pair.first; - thisItem.size = pair.second; + thisItem.size = qint64(pair.second); items += thisItem; total += thisItem.size; } @@ -614,7 +617,7 @@ PartitionSplitterWidget::computeItemsVector( const QVector< PartitionSplitterIte if ( items[ row ].size < 0.01 * total ) // If this item is smaller than 1% of everything, { // force its width to 1%. adjustedTotal -= items[ row ].size; - items[ row ].size = 0.01 * total; + items[ row ].size = qint64(0.01 * total); adjustedTotal += items[ row ].size; } } diff --git a/src/modules/partition/gui/PartitionSplitterWidget.h b/src/modules/partition/gui/PartitionSplitterWidget.h index 5065a94ca..0d2d0e233 100644 --- a/src/modules/partition/gui/PartitionSplitterWidget.h +++ b/src/modules/partition/gui/PartitionSplitterWidget.h @@ -40,9 +40,10 @@ struct PartitionSplitterItem qint64 size; Status status; - QVector< PartitionSplitterItem > children; + using ChildVector = QVector< PartitionSplitterItem >; + ChildVector children; - static PartitionSplitterItem null() { return { QString(), QColor(), false, 0, Normal }; } + static PartitionSplitterItem null() { return { QString(), QColor(), false, 0, Normal, ChildVector() }; } bool isNull() const { return itemPath.isEmpty() && size == 0 && status == Normal; } operator bool() const { return !isNull(); } @@ -59,8 +60,7 @@ public: void setSplitPartition( const QString& path, qint64 minSize, qint64 maxSize, - qint64 preferredSize, - const QString& newLabel ); + qint64 preferredSize ); qint64 splitPartitionSize() const; qint64 newPartitionSize() const; diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 5662f5e57..09eaf232d 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -41,8 +41,6 @@ typedef QHash UuidForPartitionHash; -static const char* UUID_DIR = "/dev/disk/by-uuid"; - static UuidForPartitionHash findPartitionUuids( QList < Device* > devices ) { diff --git a/src/modules/partition/jobs/MoveFileSystemJob.cpp b/src/modules/partition/jobs/MoveFileSystemJob.cpp index 9a87db91e..fbcc4641c 100644 --- a/src/modules/partition/jobs/MoveFileSystemJob.cpp +++ b/src/modules/partition/jobs/MoveFileSystemJob.cpp @@ -145,8 +145,12 @@ MoveFileSystemJob::copyBlocks( Report& report, CopyTargetDevice& target, CopySou qint64 blocksCopied = 0; - void* buffer = malloc( blockSize * source.sectorSize() ); - int percent = 0; + Q_ASSERT( blockSize > 0 ); + Q_ASSERT( source.sectorSize() > 0 ); + Q_ASSERT( blockSize * source.sectorSize() > 0 ); + + void* buffer = malloc( size_t( blockSize * source.sectorSize() ) ); + qint64 percent = 0; while ( blocksCopied < blocksToCopy ) { @@ -161,7 +165,7 @@ MoveFileSystemJob::copyBlocks( Report& report, CopyTargetDevice& target, CopySou if ( ++blocksCopied * 100 / blocksToCopy != percent ) { percent = blocksCopied * 100 / blocksToCopy; - progress( qreal( percent ) / 100. ); + progress( percent / 100. ); } } diff --git a/src/modules/partition/tests/PartitionJobTests.cpp b/src/modules/partition/tests/PartitionJobTests.cpp index fe869232b..8702e0119 100644 --- a/src/modules/partition/tests/PartitionJobTests.cpp +++ b/src/modules/partition/tests/PartitionJobTests.cpp @@ -19,6 +19,8 @@ #include +#include "utils/Units.h" + #include #include #include @@ -36,9 +38,8 @@ QTEST_GUILESS_MAIN( PartitionJobTests ) -static const qint64 MB = 1024 * 1024; - using namespace Calamares; +using CalamaresUtils::operator""_MiB; class PartitionMounter { @@ -79,7 +80,7 @@ generateTestData( qint64 size ) // Fill the array explicitly to keep Valgrind happy for ( auto it = ba.data() ; it < ba.data() + size ; ++it ) { - *it = rand() % 256; + *it = char( rand() & 0xff ); } return ba; } @@ -247,7 +248,7 @@ PartitionJobTests::testCreatePartition() freePartition = firstFreePartition( m_device->partitionTable() ); QVERIFY( freePartition ); - job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 1 * MB); + job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 1_MiB); Partition* partition1 = job->partition(); QVERIFY( partition1 ); job->updatePreview(); @@ -255,7 +256,7 @@ PartitionJobTests::testCreatePartition() freePartition = firstFreePartition( m_device->partitionTable() ); QVERIFY( freePartition ); - job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, 1 * MB); + job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, 1_MiB); Partition* partition2 = job->partition(); QVERIFY( partition2 ); job->updatePreview(); @@ -263,7 +264,7 @@ PartitionJobTests::testCreatePartition() freePartition = firstFreePartition( m_device->partitionTable() ); QVERIFY( freePartition ); - job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Fat32, 1 * MB); + job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Fat32, 1_MiB); Partition* partition3 = job->partition(); QVERIFY( partition3 ); job->updatePreview(); @@ -288,7 +289,7 @@ PartitionJobTests::testCreatePartitionExtended() freePartition = firstFreePartition( m_device->partitionTable() ); QVERIFY( freePartition ); - job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 10 * MB); + job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Primary ), FileSystem::Ext4, 10_MiB); Partition* partition1 = job->partition(); QVERIFY( partition1 ); job->updatePreview(); @@ -296,7 +297,7 @@ PartitionJobTests::testCreatePartitionExtended() freePartition = firstFreePartition( m_device->partitionTable() ); QVERIFY( freePartition ); - job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10 * MB); + job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10_MiB); job->updatePreview(); m_queue.enqueue( job_ptr( job ) ); Partition* extendedPartition = job->partition(); @@ -341,7 +342,7 @@ PartitionJobTests::testResizePartition() QFETCH( int, newStartMB ); QFETCH( int, newSizeMB ); - const qint64 sectorForMB = MB / m_device->logicalSize(); + const qint64 sectorForMB = 1_MiB / m_device->logicalSize(); qint64 oldFirst = sectorForMB * oldStartMB; qint64 oldLast = oldFirst + sectorForMB * oldSizeMB - 1; @@ -350,7 +351,7 @@ PartitionJobTests::testResizePartition() // Make the test data file smaller than the full size of the partition to // accomodate for the file system overhead - const QByteArray testData = generateTestData( ( qMin( oldSizeMB, newSizeMB ) ) * MB * 3 / 4 ); + const QByteArray testData = generateTestData( CalamaresUtils::MiBtoBytes( qMin( oldSizeMB, newSizeMB ) ) * 3 / 4 ); const QString testName = "test.data"; // Setup: create the test partition diff --git a/src/modules/welcome/checker/RequirementsChecker.cpp b/src/modules/welcome/checker/RequirementsChecker.cpp index 29112de84..ac5f5088b 100644 --- a/src/modules/welcome/checker/RequirementsChecker.cpp +++ b/src/modules/welcome/checker/RequirementsChecker.cpp @@ -27,6 +27,8 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" #include "utils/CalamaresUtilsSystem.h" +#include "utils/Units.h" + #include "JobQueue.h" #include "GlobalStorage.h" @@ -51,9 +53,10 @@ RequirementsChecker::RequirementsChecker( QObject* parent ) : QObject( parent ) , m_widget( new QWidget() ) + , m_requiredStorageGB( -1 ) + , m_requiredRamGB( -1 ) , m_actualWidget( new CheckerWidget() ) , m_verdict( false ) - , m_requiredStorageGB( -1 ) { QBoxLayout* mainLayout = new QHBoxLayout; m_widget->setLayout( mainLayout ); @@ -77,12 +80,12 @@ RequirementsChecker::RequirementsChecker( QObject* parent ) bool isRoot = false; bool enoughScreen = (availableSize.width() >= CalamaresUtils::windowPreferredWidth) && (availableSize.height() >= CalamaresUtils::windowPreferredHeight); - qint64 requiredStorageB = m_requiredStorageGB * 1073741824L; /*powers of 2*/ + qint64 requiredStorageB = CalamaresUtils::GiBtoBytes(m_requiredStorageGB); cDebug() << "Need at least storage bytes:" << requiredStorageB; if ( m_entriesToCheck.contains( "storage" ) ) enoughStorage = checkEnoughStorage( requiredStorageB ); - qint64 requiredRamB = m_requiredRamGB * 1073741824L; /*powers of 2*/ + qint64 requiredRamB = CalamaresUtils::GiBtoBytes(m_requiredRamGB); cDebug() << "Need at least ram bytes:" << requiredRamB; if ( m_entriesToCheck.contains( "ram" ) ) enoughRam = checkEnoughRam( requiredRamB );