Merge branch 'fix-keyboardq' into calamares

Various file writes were not being checked, and the code
was a bit tangled; specifically keyboardq did **not**
configure properly on KaOS and now seems ok.
main
Adriaan de Groot 6 years ago
commit c4de62cb9a

@ -179,6 +179,8 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
bool bool
SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const
{ {
cDebug() << "Writing vconsole data to" << vconsoleConfPath;
QString keymap = findConvertedKeymap( convertedKeymapPath ); QString keymap = findConvertedKeymap( convertedKeymapPath );
if ( keymap.isEmpty() ) if ( keymap.isEmpty() )
{ {
@ -205,15 +207,20 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const
file.close(); file.close();
if ( stream.status() != QTextStream::Ok ) if ( stream.status() != QTextStream::Ok )
{ {
cError() << "Could not read lines from" << file.fileName();
return false; return false;
} }
} }
// Write out the existing lines and replace the KEYMAP= line // Write out the existing lines and replace the KEYMAP= line
file.open( QIODevice::WriteOnly | QIODevice::Text ); if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
cError() << "Could not open" << file.fileName() << "for writing.";
return false;
}
QTextStream stream( &file ); QTextStream stream( &file );
bool found = false; bool found = false;
foreach ( const QString& existingLine, existingLines ) for ( const QString& existingLine : qAsConst( existingLines ) )
{ {
if ( existingLine.trimmed().startsWith( "KEYMAP=" ) ) if ( existingLine.trimmed().startsWith( "KEYMAP=" ) )
{ {
@ -233,7 +240,7 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const
stream.flush(); stream.flush();
file.close(); file.close();
cDebug() << "Written KEYMAP=" << keymap << "to vconsole.conf"; cDebug() << Logger::SubEntry << "Written KEYMAP=" << keymap << "to vconsole.conf" << stream.status();
return ( stream.status() == QTextStream::Ok ); return ( stream.status() == QTextStream::Ok );
} }
@ -242,8 +249,14 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const
bool bool
SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
{ {
cDebug() << "Writing X11 configuration to" << keyboardConfPath;
QFile file( keyboardConfPath ); QFile file( keyboardConfPath );
file.open( QIODevice::WriteOnly | QIODevice::Text ); if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
cError() << "Could not open" << file.fileName() << "for writing.";
return false;
}
QTextStream stream( &file ); QTextStream stream( &file );
stream << "# Read and parsed by systemd-localed. It's probably wise not to edit this file\n" stream << "# Read and parsed by systemd-localed. It's probably wise not to edit this file\n"
@ -287,8 +300,8 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
file.close(); file.close();
cDebug() << "Written XkbLayout" << m_layout << "; XkbModel" << m_model << "; XkbVariant" << m_variant cDebug() << Logger::SubEntry << "Written XkbLayout" << m_layout << "; XkbModel" << m_model << "; XkbVariant"
<< "to X.org file" << keyboardConfPath; << m_variant << "to X.org file" << keyboardConfPath << stream.status();
return ( stream.status() == QTextStream::Ok ); return ( stream.status() == QTextStream::Ok );
} }
@ -297,8 +310,14 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
bool bool
SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPath ) const SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPath ) const
{ {
cDebug() << "Writing default keyboard data to" << defaultKeyboardPath;
QFile file( defaultKeyboardPath ); QFile file( defaultKeyboardPath );
file.open( QIODevice::WriteOnly | QIODevice::Text ); if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
cError() << "Could not open" << defaultKeyboardPath << "for writing";
return false;
}
QTextStream stream( &file ); QTextStream stream( &file );
stream << "# KEYBOARD CONFIGURATION FILE\n\n" stream << "# KEYBOARD CONFIGURATION FILE\n\n"
@ -313,8 +332,8 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
file.close(); file.close();
cDebug() << "Written XKBMODEL" << m_model << "; XKBLAYOUT" << m_layout << "; XKBVARIANT" << m_variant cDebug() << Logger::SubEntry << "Written XKBMODEL" << m_model << "; XKBLAYOUT" << m_layout << "; XKBVARIANT"
<< "to /etc/default/keyboard file" << defaultKeyboardPath; << m_variant << "to /etc/default/keyboard file" << defaultKeyboardPath << stream.status();
return ( stream.status() == QTextStream::Ok ); return ( stream.status() == QTextStream::Ok );
} }
@ -329,9 +348,29 @@ SetKeyboardLayoutJob::exec()
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
QDir destDir( gs->value( "rootMountPoint" ).toString() ); QDir destDir( gs->value( "rootMountPoint" ).toString() );
{
// Get the path to the destination's /etc/vconsole.conf // Get the path to the destination's /etc/vconsole.conf
QString vconsoleConfPath = destDir.absoluteFilePath( "etc/vconsole.conf" ); QString vconsoleConfPath = destDir.absoluteFilePath( "etc/vconsole.conf" );
// Get the path to the destination's path to the converted key mappings
QString convertedKeymapPath = m_convertedKeymapPath;
if ( !convertedKeymapPath.isEmpty() )
{
while ( convertedKeymapPath.startsWith( '/' ) )
{
convertedKeymapPath.remove( 0, 1 );
}
convertedKeymapPath = destDir.absoluteFilePath( convertedKeymapPath );
}
if ( !writeVConsoleData( vconsoleConfPath, convertedKeymapPath ) )
{
return Calamares::JobResult::error( tr( "Failed to write keyboard configuration for the virtual console." ),
tr( "Failed to write to %1" ).arg( vconsoleConfPath ) );
}
}
{
// Get the path to the destination's /etc/X11/xorg.conf.d/00-keyboard.conf // Get the path to the destination's /etc/X11/xorg.conf.d/00-keyboard.conf
QString xorgConfDPath; QString xorgConfDPath;
QString keyboardConfPath; QString keyboardConfPath;
@ -352,37 +391,29 @@ SetKeyboardLayoutJob::exec()
} }
destDir.mkpath( xorgConfDPath ); destDir.mkpath( xorgConfDPath );
QString defaultKeyboardPath; if ( !writeX11Data( keyboardConfPath ) )
if ( QDir( destDir.absoluteFilePath( "etc/default" ) ).exists() )
{ {
defaultKeyboardPath = destDir.absoluteFilePath( "etc/default/keyboard" ); return Calamares::JobResult::error( tr( "Failed to write keyboard configuration for X11." ),
tr( "Failed to write to %1" ).arg( keyboardConfPath ) );
}
} }
// Get the path to the destination's path to the converted key mappings
QString convertedKeymapPath = m_convertedKeymapPath;
if ( !convertedKeymapPath.isEmpty() )
{ {
while ( convertedKeymapPath.startsWith( '/' ) ) QString defaultKeyboardPath;
if ( QDir( destDir.absoluteFilePath( "etc/default" ) ).exists() )
{ {
convertedKeymapPath.remove( 0, 1 ); defaultKeyboardPath = destDir.absoluteFilePath( "etc/default/keyboard" );
}
convertedKeymapPath = destDir.absoluteFilePath( convertedKeymapPath );
} }
if ( !writeVConsoleData( vconsoleConfPath, convertedKeymapPath ) )
return Calamares::JobResult::error( tr( "Failed to write keyboard configuration for the virtual console." ),
tr( "Failed to write to %1" ).arg( vconsoleConfPath ) );
if ( !writeX11Data( keyboardConfPath ) )
return Calamares::JobResult::error( tr( "Failed to write keyboard configuration for X11." ),
tr( "Failed to write to %1" ).arg( keyboardConfPath ) );
if ( !defaultKeyboardPath.isEmpty() && m_writeEtcDefaultKeyboard ) if ( !defaultKeyboardPath.isEmpty() && m_writeEtcDefaultKeyboard )
{ {
if ( !writeDefaultKeyboardData( defaultKeyboardPath ) ) if ( !writeDefaultKeyboardData( defaultKeyboardPath ) )
{
return Calamares::JobResult::error( return Calamares::JobResult::error(
tr( "Failed to write keyboard configuration to existing /etc/default directory." ), tr( "Failed to write keyboard configuration to existing /etc/default directory." ),
tr( "Failed to write to %1" ).arg( keyboardConfPath ) ); tr( "Failed to write to %1" ).arg( defaultKeyboardPath ) );
}
}
} }
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();

Loading…
Cancel
Save