Git commit 5bfc946b472261b9943085d9c2db0d6ac90452a7 by Konstantinos Smanis. Committed on 22/10/2013 at 20:43. Pushed by ksmanis into branch 'master'. Unified password dialog on startup. Ask for password only once (on startup), not every time a privileged action is about to run. Sacrifice fine-tuned privilege escalation for the sake of simplicity. I doubt any administrator will actually notice, plus the users won't be confused with all these password dialogs. We'll see how this idea pans out. M +0 -7 config.h.cmake M +12 -1 src/common.h M +51 -43 src/helper/helper.cpp M +0 -1 src/helper/helper.h M +0 -73 src/helper/kcmgrub2.actions M +92 -95 src/kcm_grub2.cpp M +2 -8 src/kcm_grub2.h http://commits.kde.org/kcm-grub2/5bfc946b472261b9943085d9c2db0d6ac90452a7 diff --git a/config.h.cmake b/config.h.cmake index 5d57a67..2270142 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -18,11 +18,4 @@ #define GRUB_ENV "@GRUB_ENV@" #define GRUB_MEMTEST "@GRUB_MEMTEST@" = -enum GrubFile { - GrubMenuFile, - GrubConfigurationFile, - GrubEnvironmentFile, - GrubMemtestFile -}; - #endif diff --git a/src/common.h b/src/common.h index 100cefc..153d876 100644 --- a/src/common.h +++ b/src/common.h @@ -19,7 +19,18 @@ #define COMMON_H = //Qt -class QString; +#include + +enum LoadOperation { + NoOperation =3D 0x0, + MenuFile =3D 0x1, + ConfigurationFile =3D 0x2, + EnvironmentFile =3D 0x4, + MemtestFile =3D 0x8, + Vbe =3D 0x10 +}; +Q_DECLARE_FLAGS(LoadOperations, LoadOperation) +Q_DECLARE_OPERATORS_FOR_FLAGS(LoadOperations) = QString quoteWord(const QString &word); QString unquoteWord(const QString &word); diff --git a/src/helper/helper.cpp b/src/helper/helper.cpp index 5164db2..a40f879 100644 --- a/src/helper/helper.cpp +++ b/src/helper/helper.cpp @@ -32,6 +32,7 @@ #include = //Project +#include "../common.h" #include "../config.h" #if HAVE_HD #undef slots @@ -123,57 +124,64 @@ ActionReply Helper::install(QVariantMap args) ActionReply Helper::load(QVariantMap args) { ActionReply reply; - QString fileName; - switch (args.value("grubFile").toInt()) { - case GrubMenuFile: - fileName =3D GRUB_MENU; - break; - case GrubConfigurationFile: - fileName =3D GRUB_CONFIG; - break; - case GrubEnvironmentFile: - fileName =3D GRUB_ENV; - break; - case GrubMemtestFile: + LoadOperations operations =3D (LoadOperations)(args.value("operations"= ).toInt()); + + if (operations.testFlag(MenuFile)) { + QFile file(GRUB_MENU); + bool ok =3D file.open(QIODevice::ReadOnly | QIODevice::Text); + reply.addData(QLatin1String("menuSuccess"), ok); + if (ok) { + reply.addData(QLatin1String("menuContents"), file.readAll()); + } else { + reply.addData(QLatin1String("menuError"), file.error()); + reply.addData(QLatin1String("menuErrorString"), file.errorStri= ng()); + } + } + if (operations.testFlag(ConfigurationFile)) { + QFile file(GRUB_CONFIG); + bool ok =3D file.open(QIODevice::ReadOnly | QIODevice::Text); + reply.addData(QLatin1String("configSuccess"), ok); + if (ok) { + reply.addData(QLatin1String("configContents"), file.readAll()); + } else { + reply.addData(QLatin1String("configError"), file.error()); + reply.addData(QLatin1String("configErrorString"), file.errorSt= ring()); + } + } + if (operations.testFlag(EnvironmentFile)) { + QFile file(GRUB_ENV); + bool ok =3D file.open(QIODevice::ReadOnly | QIODevice::Text); + reply.addData(QLatin1String("envSuccess"), ok); + if (ok) { + reply.addData(QLatin1String("envContents"), file.readAll()); + } else { + reply.addData(QLatin1String("envError"), file.error()); + reply.addData(QLatin1String("envErrorString"), file.errorStrin= g()); + } + } + if (operations.testFlag(MemtestFile)) { bool memtest =3D QFile::exists(GRUB_MEMTEST); - reply.addData("memtest", memtest); + reply.addData(QLatin1String("memtest"), memtest); if (memtest) { - reply.addData("memtestOn", (bool)(QFile::permissions(GRUB_MEMT= EST) & (QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther))); + reply.addData(QLatin1String("memtestOn"), (bool)(QFile::permis= sions(GRUB_MEMTEST) & (QFile::ExeOwner | QFile::ExeGroup | QFile::ExeOther)= )); } - return reply; - } - - QFile file(fileName); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - reply =3D ActionReply::HelperErrorReply; - reply.addData("errorDescription", file.errorString()); - return reply; } - reply.addData("rawFileContents", file.readAll()); - return reply; -} -ActionReply Helper::probevbe(QVariantMap args) -{ - Q_UNUSED(args) - ActionReply reply; - #if HAVE_HD - QStringList gfxmodes; - hd_data_t hd_data; - memset(&hd_data, 0, sizeof(hd_data)); - hd_t *hd =3D hd_list(&hd_data, hw_framebuffer, 1, NULL); - for (hd_res_t *res =3D hd->res; res; res =3D res->next) { - if (res->any.type =3D=3D res_framebuffer) { - gfxmodes +=3D QString("%1x%2x%3").arg(QString::number(res->fra= mebuffer.width), QString::number(res->framebuffer.height), QString::number(= res->framebuffer.colorbits)); + if (operations.testFlag(Vbe)) { + QStringList gfxmodes; + hd_data_t hd_data; + memset(&hd_data, 0, sizeof(hd_data)); + hd_t *hd =3D hd_list(&hd_data, hw_framebuffer, 1, NULL); + for (hd_res_t *res =3D hd->res; res; res =3D res->next) { + if (res->any.type =3D=3D res_framebuffer) { + gfxmodes +=3D QString("%1x%2x%3").arg(QString::number(res-= >framebuffer.width), QString::number(res->framebuffer.height), QString::num= ber(res->framebuffer.colorbits)); + } } + hd_free_hd_list(hd); + hd_free_hd_data(&hd_data); + reply.addData("gfxmodes", gfxmodes); } - hd_free_hd_list(hd); - hd_free_hd_data(&hd_data); - reply.addData("gfxmodes", gfxmodes); -#else - reply =3D ActionReply::HelperErrorReply; #endif - return reply; } ActionReply Helper::save(QVariantMap args) diff --git a/src/helper/helper.h b/src/helper/helper.h index 2ede191..11e8935 100644 --- a/src/helper/helper.h +++ b/src/helper/helper.h @@ -33,7 +33,6 @@ public Q_SLOTS: ActionReply defaults(QVariantMap args); ActionReply install(QVariantMap args); ActionReply load(QVariantMap args); - ActionReply probevbe(QVariantMap args); ActionReply save(QVariantMap args); }; = diff --git a/src/helper/kcmgrub2.actions b/src/helper/kcmgrub2.actions index 839e524..2089070 100644 --- a/src/helper/kcmgrub2.actions +++ b/src/helper/kcmgrub2.actions @@ -259,79 +259,6 @@ Description[zh_TW]=3D=E8=BC=89=E5=85=A5 GRUB2 =E9=96= =8B=E6=A9=9F=E8=BC=89=E5=85=A5=E5=99=A8=E8=A8=AD=E5=AE=9A=E9=9C=80=E8=A6=81= =E7=AE=A1=E7=90=86=E8=80=85=E6=AC=8A=E9=99=90 Policy=3Dauth_admin Persistence=3Dsession = -[org.kde.kcontrol.kcmgrub2.probevbe] -Name=3DProbe VESA BIOS Extensions -Name[bs]=3DIspitaj VESA BIOS pro=C5=A1irenja -Name[ca]=3DProva les extensions VESA del BIOS -Name[ca@valencia]=3DProva les extensions VESA del BIOS -Name[cs]=3DProzkoumat roz=C5=A1=C3=AD=C5=99eni VESA BIOS (VBE) -Name[da]=3DS=C3=B8g efter VESA BIOS-udvidelser -Name[de]=3DVESA-BIOS-Erweiterungen ermitteln -Name[el]=3D=CE=88=CE=BB=CE=B5=CE=B3=CF=87=CE=BF=CF=82 =CE=B3=CE=B9=CE=B1 V= ESA BIOS =CE=B5=CF=80=CE=B5=CE=BA=CF=84=CE=AC=CF=83=CE=B5=CE=B9=CF=82 -Name[es]=3DExaminar las extensiones BIOS de VESA -Name[et]=3DVESA BIOS-e laiendite kontrollimine -Name[fi]=3DTunnustele VESA BIOS -laajennukset -Name[fr]=3DD=C3=A9tecter les extensions =C2=AB=C2=A0BIOS VESA=C2=A0=C2=BB -Name[ga]=3DFiosraigh Eis=C3=ADnteachta=C3=AD BIOS VESA -Name[gl]=3DProbar os engadidos VESA BIOS -Name[hu]=3DVESA BIOS kiterjeszt=C3=A9sek vizsg=C3=A1lata -Name[it]=3DSonda le estensioni per il BIOS della VESA -Name[lt]=3DTikrinti VESA BIOS pl=C4=97tinius -Name[mr]=3DVESA BIOS =E0=A4=B5=E0=A4=BF=E0=A4=B8=E0=A5=8D=E0=A4=A4=E0=A4= =BE=E0=A4=B0=E0=A4=A3=E0=A5=87 =E0=A4=B6=E0=A5=8B=E0=A4=A7=E0=A4=BE -Name[nb]=3DSe etter VESA BIOS-utvidelser -Name[nds]=3DVESA-BIOS-Verwiedern opdecken -Name[nl]=3DVESA BIOS extensies aftasten -Name[pa]=3DVESA BIOS =E0=A8=87=E0=A8=95=E0=A8=B8=E0=A8=9F=E0=A9=88=E0=A8= =A8=E0=A8=B8=E0=A8=BC=E0=A8=A8 =E0=A8=B2=E0=A8=88 =E0=A8=AA=E0=A9=9C=E0=A8= =A4=E0=A8=BE=E0=A8=B2 -Name[pl]=3DWykryj rozszerzenia VESA BIOS -Name[pt]=3DTestar as extens=C3=B5es da BIOS para o VESA -Name[pt_BR]=3DTestar as extens=C3=B5es da BIOS para o VESA -Name[ro]=3DSondeaz=C4=83 extensiile BIOS=C2=A0VESA -Name[ru]=3D=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0 =D1=80=D0=B0= =D1=81=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D0=B8=D0=B9 BIOS =D0=B2 =D1=81=D1=82= =D0=B0=D0=BD=D0=B4=D0=B0=D1=80=D1=82=D0=B5 VESA (VBE) -Name[sk]=3DVysk=C3=BA=C5=A1a=C5=A5 roz=C5=A1=C3=ADrenia VESA BIOSu -Name[sl]=3DPreizkusi raz=C5=A1iritve VESA BIOS -Name[sv]=3DS=C3=B6k efter VESA BIOS-ut=C3=B6kningar -Name[tr]=3DVESA BIOS Uzant=C4=B1lar=C4=B1n=C4=B1 Ara=C5=9Ft=C4=B1r -Name[uk]=3D=D0=92=D0=B8=D1=8F=D0=B2=D0=BB=D0=B5=D0=BD=D0=BD=D1=8F =D1=80= =D0=BE=D0=B7=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D1=8C BIOS VESA -Name[x-test]=3DxxProbe VESA BIOS Extensionsxx -Name[zh_CN]=3D=E6=8E=A2=E6=B5=8B VESA BIOS =E6=89=A9=E5=B1=95 -Name[zh_TW]=3D=E5=81=B5=E6=B8=AC VESA BIOS =E5=BB=B6=E4=BC=B8 -Description=3DAdministrator authorization is required to probe VESA BIOS E= xtensions -Description[bs]=3DAdministratorska potvrda je potrebna za testiranje VESA = BIOS pro=C5=A1irenja -Description[ca]=3DEs requereix autoritzaci=C3=B3 de l'administrador per a = provar les extensions VESA del BIOS -Description[ca@valencia]=3DEs requereix autoritzaci=C3=B3 de l'administrad= or per a provar les extensions VESA del BIOS -Description[cs]=3DPro prozkoum=C3=A1n=C3=AD roz=C5=A1=C3=AD=C5=99en=C3=AD = VESA BIOS (VBE) je pot=C5=99eba opr=C3=A1vn=C4=9Bn=C3=AD administr=C3=A1tora -Description[da]=3DAdministrator-godkendelse kr=C3=A6ves for at s=C3=B8ge e= fter VESA BIOS-udvidelser -Description[de]=3DZur Ermittlung der VESA-BIOS-Erweiterungen sind Systemve= rwalterrechte erforderlich. -Description[el]=3D=CE=91=CF=80=CE=B1=CE=B9=CF=84=CE=B5=CE=AF=CF=84=CE=B1= =CE=B9 =CE=B5=CE=BE=CE=BF=CF=85=CF=83=CE=B9=CE=BF=CE=B4=CF=8C=CF=84=CE=B7= =CF=83=CE=B7 =CE=B4=CE=B9=CE=B1=CF=87=CE=B5=CE=B9=CF=81=CE=B9=CF=83=CF=84= =CE=AE =CE=B3=CE=B9=CE=B1 =CF=84=CE=BF=CE=BD =CE=AD=CE=BB=CE=B5=CE=B3=CF=87= =CE=BF VESA BIOS =CE=B5=CF=80=CE=B5=CE=BA=CF=84=CE=AC=CF=83=CE=B5=CF=89=CE= =BD -Description[es]=3DSe requiere la autorizaci=C3=B3n del administrador para = examinar las extensiones BIOS de VESA -Description[et]=3DVESA BIOS-e laiendite kontrollimiseks on vajalik autenti= mine administraatorina -Description[fi]=3DVESA BIOS -laajennusten tunnusteleminen vaatii p=C3=A4= =C3=A4k=C3=A4ytt=C3=A4j=C3=A4n oikeudet -Description[fr]=3DL'autorisation de l'administrateur est requise pour d=C3= =A9tecter les extensions BIOS VESA -Description[ga]=3DIs =C3=A9 riarth=C3=B3ir an ch=C3=B3rais amh=C3=A1in at= =C3=A1=C2=A0in ann Eis=C3=ADnteachta=C3=AD BIOS VESA a fhiosr=C3=BA -Description[gl]=3DPrec=C3=ADsase a autorizaci=C3=B3n do administrador para= probar os engadidos VESA BIOS -Description[hu]=3DRendszergazdai jogosults=C3=A1gok sz=C3=BCks=C3=A9gesek = a VESA BIOS kiterjeszt=C3=A9sek vizsg=C3=A1lat=C3=A1hoz -Description[it]=3DSono i richiesti i privilegi amministrativi per sondare = le estensioni per il BIOS della VESA -Description[lt]=3DAdministratoriaus =C4=AFgaliojimas reikalingas, kad pati= krinti VESA BIOS pl=C4=97tinius -Description[mr]=3DVESA BIOS =E0=A4=B5=E0=A4=BF=E0=A4=B8=E0=A5=8D=E0=A4=A4= =E0=A4=BE=E0=A4=B0=E0=A4=A3=E0=A5=87 =E0=A4=B6=E0=A5=8B=E0=A4=A7=E0=A4=A3= =E0=A5=8D=E0=A4=AF=E0=A4=BE=E0=A4=95=E0=A4=B0=E0=A4=BF=E0=A4=A4=E0=A4=BE = =E0=A4=B5=E0=A5=8D=E0=A4=AF=E0=A4=B5=E0=A4=B8=E0=A5=8D=E0=A4=A5=E0=A4=BE=E0= =A4=AA=E0=A4=95=E0=A4=BE=E0=A4=9A=E0=A5=80 =E0=A4=AA=E0=A4=B0=E0=A4=B5=E0= =A4=BE=E0=A4=A8=E0=A4=97=E0=A5=80 =E0=A4=86=E0=A4=B5=E0=A4=B6=E0=A5=8D=E0= =A4=AF=E0=A4=95 =E0=A4=86=E0=A4=B9=E0=A5=87 -Description[nb]=3DDet kreves autorisasjon som administrator for =C3=A5 s= =C3=B8ke etter VESA BIOS-utvidcelser -Description[nds]=3DDe VESA-BIOS-Verwiedern laat sik bloots mit Systeempleg= er-Verl=C3=B6=C3=B6f opdecken. -Description[nl]=3DAutorisatie van systeembeheerder is vereist om VESA BIOS= extensies af te tasten -Description[pl]=3DDo wykrycia rozszerze=C5=84 VESA BIOS potrzebne s=C4=85 = uprawnienia administratora -Description[pt]=3D=C3=89 necess=C3=A1ria a autoriza=C3=A7=C3=A3o do admini= strador para testar a extens=C3=B5es da BIOS para o VESA -Description[pt_BR]=3D=C3=89 necess=C3=A1ria a autoriza=C3=A7=C3=A3o do adm= inistrador para testar a extens=C3=B5es da BIOS para o VESA -Description[ro]=3DEste necesar=C4=83 autorizarea ca administrator pentru a= sonda extensiile BIOS=C2=A0VESA -Description[ru]=3D=D0=94=D0=BB=D1=8F =D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80= =D0=BA=D0=B8 =D1=80=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D0=B8=D0=B9 B= IOS =D0=B2 =D1=81=D1=82=D0=B0=D0=BD=D0=B4=D0=B0=D1=80=D1=82=D0=B5 VESA (VBE= ) =D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4=D0=B8=D0=BC=D1=8B =D0=BF=D1=80= =D0=B0=D0=B2=D0=B0 =D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=B8=D1=81=D1=82=D1=80= =D0=B0=D1=82=D0=BE=D1=80=D0=B0 -Description[sk]=3DVy=C5=BEaduje sa overenie administr=C3=A1tora na vysk=C3= =BA=C5=A1anie roz=C5=A1=C3=ADren=C3=AD VESA BIOSu -Description[sl]=3DZa preizkus raz=C5=A1iritev VESA BIOS GRUB2 je zahtevana= pooblastitev skrbnika -Description[sv]=3DAdministrat=C3=B6rsbeh=C3=B6righet kr=C3=A4vs f=C3=B6r a= tt s=C3=B6ka efter VESA BIOS-ut=C3=B6kningar -Description[tr]=3DVESA BIOS Uzant=C4=B1lar=C4=B1n=C4=B1 ara=C5=9Ft=C4=B1rm= ak i=C3=A7in y=C3=B6netici yetkilendirmesi gerekli -Description[uk]=3D=D0=94=D0=BB=D1=8F =D0=B2=D0=B8=D1=8F=D0=B2=D0=BB=D0=B5= =D0=BD=D0=BD=D1=8F =D1=80=D0=BE=D0=B7=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D1=8C B= IOS VESA =D1=81=D0=BB=D1=96=D0=B4 =D0=BD=D0=B0=D0=B1=D1=83=D1=82=D0=B8 =D0= =BF=D1=80=D0=B0=D0=B2 =D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D1=83 =D0=B0=D0= =B4=D0=BC=D1=96=D0=BD=D1=96=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B0 -Description[x-test]=3DxxAdministrator authorization is required to probe V= ESA BIOS Extensionsxx -Description[zh_CN]=3D=E6=8E=A2=E6=B5=8B VESA BIOS =E6=89=A9=E5=B1=95=E9=9C= =80=E8=A6=81=E7=AE=A1=E7=90=86=E5=91=98=E6=9D=83=E9=99=90 -Description[zh_TW]=3D=E5=81=B5=E6=B8=AC VESA BIOS =E5=BB=B6=E4=BC=B8=E9=9C= =80=E8=A6=81=E7=AE=A1=E7=90=86=E8=80=85=E6=AC=8A=E9=99=90 -Policy=3Dauth_admin -Persistence=3Dsession - [org.kde.kcontrol.kcmgrub2.save] Name=3DSave the GRUB2 Bootloader settings Name[bs]=3DSnimie postavke GRUB2 pokreta=C4=8Da sistema diff --git a/src/kcm_grub2.cpp b/src/kcm_grub2.cpp index 1ed7e57..68a0ef9 100644 --- a/src/kcm_grub2.cpp +++ b/src/kcm_grub2.cpp @@ -32,13 +32,13 @@ #include #include #include -#include #include #include #include = //Project #include "common.h" +#include "config.h" #if HAVE_IMAGEMAGICK #include "convertDlg.h" #endif @@ -93,13 +93,8 @@ void KCMGRUB2::defaults() } void KCMGRUB2::load() { - readEntries(); - readSettings(); - readEnv(); - readMemtest(); -#if HAVE_HD - readResolutions(); -#endif + readAll(); + QString grubDefault =3D unquoteWord(m_settings.value("GRUB_DEFAULT")); if (grubDefault =3D=3D QLatin1String("saved")) { grubDefault =3D (m_env.value("saved_entry").isEmpty() ? "0" : m_en= v.value("saved_entry")); @@ -927,107 +922,103 @@ void KCMGRUB2::setupConnections() connect(ui->kpushbutton_install, SIGNAL(clicked(bool)), this, SLOT(slo= tInstallBootloader())); } = -ActionReply KCMGRUB2::loadFile(GrubFile grubFile) -{ - Action loadAction("org.kde.kcontrol.kcmgrub2.load"); - loadAction.setHelperID("org.kde.kcontrol.kcmgrub2"); - loadAction.addArgument("grubFile", grubFile); -#if KDE_IS_VERSION(4,6,0) - loadAction.setParentWidget(this); -#endif - - ActionReply reply =3D loadAction.execute(); - processReply(reply); - return reply; -} -QString KCMGRUB2::readFile(GrubFile grubFile) +bool KCMGRUB2::readFile(const QString &fileName, QByteArray &fileContents) { - QString fileName; - switch (grubFile) { - case GrubMenuFile: - fileName =3D GRUB_MENU; - break; - case GrubConfigurationFile: - fileName =3D GRUB_CONFIG; - break; - case GrubEnvironmentFile: - fileName =3D GRUB_ENV; - break; - case GrubMemtestFile: - return QString(); - } - QFile file(fileName); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream stream(&file); - return stream.readAll(); - } - - ActionReply reply =3D loadFile(grubFile); - if (reply.failed()) { - kError() << "Error loading:" << fileName; - kError() << "Error description:" << reply.errorDescription(); - return QString(); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + kDebug() << "Failed to read file:" << fileName; + kDebug() << "Error code:" << file.error(); + kDebug() << "Error description:" << file.errorString(); + kDebug() << "The helper will now attempt to read this file."; + return false; } - return QString::fromLocal8Bit(reply.data().value("rawFileContents").to= ByteArray()); -} -void KCMGRUB2::readEntries() -{ - QString fileContents =3D readFile(GrubMenuFile); - - m_entries.clear(); - parseEntries(fileContents); -} -void KCMGRUB2::readSettings() -{ - QString fileContents =3D readFile(GrubConfigurationFile); - - m_settings.clear(); - parseSettings(fileContents); + fileContents =3D file.readAll(); + return true; } -void KCMGRUB2::readEnv() +void KCMGRUB2::readAll() { - QString fileContents =3D readFile(GrubEnvironmentFile); + QByteArray fileContents; + LoadOperations operations =3D NoOperation; = - m_env.clear(); - parseEnv(fileContents); -} -void KCMGRUB2::readMemtest() -{ - bool memtest =3D QFile::exists(GRUB_MEMTEST); - if (memtest) { + if (readFile(GRUB_MENU, fileContents)) { + parseEntries(QString::fromUtf8(fileContents.constData())); + } else { + operations |=3D MenuFile; + } + if (readFile(GRUB_CONFIG, fileContents)) { + parseSettings(QString::fromUtf8(fileContents.constData())); + } else { + operations |=3D ConfigurationFile; + } + if (readFile(GRUB_ENV, fileContents)) { + parseEnv(QString::fromUtf8(fileContents.constData())); + } else { + operations |=3D EnvironmentFile; + } + if (QFile::exists(GRUB_MEMTEST)) { m_memtest =3D true; m_memtestOn =3D (bool)(QFile::permissions(GRUB_MEMTEST) & (QFile::= ExeOwner | QFile::ExeGroup | QFile::ExeOther)); - return; + } else { + operations |=3D MemtestFile; } +#if HAVE_HD + operations |=3D Vbe; +#endif = - ActionReply reply =3D loadFile(GrubMemtestFile); - if (reply.failed()) { - kError() << "Error loading:" << GRUB_MEMTEST; - kError() << "Error description:" << reply.errorDescription(); - return; - } - m_memtest =3D reply.data().value("memtest").toBool(); - if (m_memtest) { - m_memtestOn =3D reply.data().value("memtestOn").toBool(); - } -} -void KCMGRUB2::readResolutions() -{ - Action probeVbeAction("org.kde.kcontrol.kcmgrub2.probevbe"); - probeVbeAction.setHelperID("org.kde.kcontrol.kcmgrub2"); + if (operations) { + Action loadAction("org.kde.kcontrol.kcmgrub2.load"); + loadAction.setHelperID("org.kde.kcontrol.kcmgrub2"); + loadAction.addArgument("operations", (int)(operations)); #if KDE_IS_VERSION(4,6,0) - probeVbeAction.setParentWidget(this); + loadAction.setParentWidget(this); #endif = - ActionReply reply =3D probeVbeAction.execute(); - processReply(reply); - if (reply.failed()) { - return; - } + ActionReply reply =3D loadAction.execute(); + processReply(reply); + if (reply.failed()) { + kError() << "KAuth error!"; + kError() << "Error code:" << reply.errorCode(); + kError() << "Error description:" << reply.errorDescription(); + return; + } = - m_resolutions.clear(); - m_resolutions =3D reply.data().value("gfxmodes").toStringList(); + if (operations.testFlag(MenuFile)) { + if (reply.data().value(QLatin1String("menuSuccess")).toBool())= { + parseEntries(QString::fromUtf8(reply.data().value(QLatin1S= tring("menuContents")).toByteArray().constData())); + } else { + kError() << "Helper failed to read file:" << GRUB_MENU; + kError() << "Error code:" << reply.data().value(QLatin1Str= ing("menuError")).toInt(); + kError() << "Error description:" << reply.data().value(QLa= tin1String("menuErrorString")).toString(); + } + } + if (operations.testFlag(ConfigurationFile)) { + if (reply.data().value(QLatin1String("configSuccess")).toBool(= )) { + parseSettings(QString::fromUtf8(reply.data().value(QLatin1= String("configContents")).toByteArray().constData())); + } else { + kError() << "Helper failed to read file:" << GRUB_CONFIG; + kError() << "Error code:" << reply.data().value(QLatin1Str= ing("configError")).toInt(); + kError() << "Error description:" << reply.data().value(QLa= tin1String("configErrorString")).toString(); + } + } + if (operations.testFlag(EnvironmentFile)) { + if (reply.data().value(QLatin1String("envSuccess")).toBool()) { + parseEnv(QString::fromUtf8(reply.data().value(QLatin1Strin= g("envContents")).toByteArray().constData())); + } else { + kError() << "Helper failed to read file:" << GRUB_ENV; + kError() << "Error code:" << reply.data().value(QLatin1Str= ing("envError")).toInt(); + kError() << "Error description:" << reply.data().value(QLa= tin1String("envErrorString")).toString(); + } + } + if (operations.testFlag(MemtestFile)) { + m_memtest =3D reply.data().value(QLatin1String("memtest")).toB= ool(); + if (m_memtest) { + m_memtestOn =3D reply.data().value(QLatin1String("memtestO= n")).toBool(); + } + } + if (operations.testFlag(Vbe)) { + m_resolutions =3D reply.data().value(QLatin1String("gfxmodes")= ).toStringList(); + } + } } = void KCMGRUB2::sortResolutions() @@ -1150,6 +1141,8 @@ void KCMGRUB2::parseEntries(const QString &config) QList submenus; QString word, configStr =3D config; QTextStream stream(&configStr, QIODevice::ReadOnly | QIODevice::Text); + + m_entries.clear(); while (!stream.atEnd()) { //Read the first word of the line stream >> word; @@ -1215,6 +1208,8 @@ void KCMGRUB2::parseSettings(const QString &config) { QString line, configStr =3D config; QTextStream stream(&configStr, QIODevice::ReadOnly | QIODevice::Text); + + m_settings.clear(); while (!stream.atEnd()) { line =3D stream.readLine().trimmed(); if (line.startsWith(QLatin1String("GRUB_"))) { @@ -1226,6 +1221,8 @@ void KCMGRUB2::parseEnv(const QString &config) { QString line, configStr =3D config; QTextStream stream(&configStr, QIODevice::ReadOnly | QIODevice::Text); + + m_env.clear(); while (!stream.atEnd()) { line =3D stream.readLine().trimmed(); if (line.startsWith('#')) { diff --git a/src/kcm_grub2.h b/src/kcm_grub2.h index 886a826..014847f 100644 --- a/src/kcm_grub2.h +++ b/src/kcm_grub2.h @@ -30,7 +30,6 @@ namespace KAuth using namespace KAuth; = //Project -#include "config.h" class Entry; = //Ui @@ -85,13 +84,8 @@ private: void setupObjects(); void setupConnections(); = - ActionReply loadFile(GrubFile grubFile); - QString readFile(GrubFile grubFile); - void readEntries(); - void readSettings(); - void readEnv(); - void readMemtest(); - void readResolutions(); + bool readFile(const QString &fileName, QByteArray &fileContents); + void readAll(); = void sortResolutions(); void showResolutions();