// Theme installation code inspired by kcm_icon void KDMThemeWidget::installNewTheme() { QString url; KUrlRequesterDialog fileRequester(url, i18n("Drag or Type Theme URL"), this); fileRequester.urlRequester()->setMode(KFile::File | KFile::Directory | KFile::ExistingOnly); KUrl themeURL = fileRequester.getUrl(); if (themeURL.isEmpty()) return; #if 0 if (themeURL.isLocalFile() && QDir(themeURL.toLocalFile()).exists()) { insertTheme(themeURL.toLocalFile()); emit changed(); return; } #endif QString themeTmpFile; if (!KIO::NetAccess::download(themeURL, themeTmpFile, this)) { QString sorryText; if (themeURL.isLocalFile()) sorryText = i18n("Unable to find the KDM theme archive %1.", themeURL.prettyUrl()); else sorryText = i18n("Unable to download the KDM theme archive;\n" "please check that address %1 is correct.", themeURL.prettyUrl()); KMessageBox::sorry(this, sorryText); return; } QList<const KArchiveDirectory *> foundThemes; KTar archive(themeTmpFile); archive.open(QIODevice::ReadOnly); const KArchiveDirectory *archDir = archive.directory(); foreach (const QString &ent, archDir->entries()) { const KArchiveEntry *possibleDir = archDir->entry(ent); if (possibleDir->isDirectory()) { const KArchiveDirectory *subDir = static_cast<const KArchiveDirectory *>(possibleDir); if (subDir->entry("KdmGreeterTheme.desktop")) foundThemes.append(subDir); } } if (foundThemes.isEmpty()) KMessageBox::error(this, i18n("The file is not a valid KDM theme archive.")); else { KProgressDialog progressDiag(this, i18nc("@title:window", "Installing KDM themes"), QString()); progressDiag.setModal(true); progressDiag.setAutoClose(true); progressDiag.progressBar()->setMaximum(foundThemes.size()); progressDiag.show(); KTempDir themesTempDir(KStandardDirs::locateLocal("tmp", "kdmthemes")); QStringList themesTempDirs, themesDirs; foreach (const KArchiveDirectory *ard, foundThemes) { progressDiag.setLabelText( i18nc("@info:progress", "<qt>Unpacking <strong>%1</strong> theme</qt>", ard->name())); themesTempDirs.append(themesTempDir.name() + ard->name()); themesDirs.append(themeDir + ard->name()); ard->copyTo(themesTempDirs.last(), true); progressDiag.progressBar()->setValue(progressDiag.progressBar()->value() + 1); if (progressDiag.wasCancelled()) break; } progressDiag.setLabelText(i18nc("@info:progress", "<qt>Installing the themes</qt>")); QVariantMap helperargs; QVariantMap returnedData; helperargs["subaction"] = Helper::InstallThemes; helperargs["themes"] = themesTempDirs; if (executeThemeAction(parentWidget(), helperargs, &returnedData)) { QString errorMessage = i18n("There were errors while installing the following themes:\n"); QStringList failedThemes = returnedData["failedthemes"].toStringList(); foreach (const QString &path, failedThemes) errorMessage += path + '\n'; KMessageBox::error(this, errorMessage); }
KDMThemeWidget::KDMThemeWidget(QWidget *parent) : QWidget(parent) { QGridLayout *ml = new QGridLayout(this); ml->setSizeConstraint(QLayout::SetMinAndMaxSize); ml->setSpacing(KDialog::spacingHint()); ml->setMargin(KDialog::marginHint()); themeWidget = new QTreeWidget(this); themeWidget->setHeaderLabels(QStringList() << i18nc("@title:column", "Theme") << i18nc("@title:column", "Author")); themeWidget->setSortingEnabled(true); themeWidget->sortItems(0, Qt::AscendingOrder); themeWidget->setRootIsDecorated(false); themeWidget->setWhatsThis(i18n("This is a list of installed themes.\n" "Click the one to be used.")); ml->addWidget(themeWidget, 0, 0, 2, 4); preview = new QLabel(this); preview->setFixedSize(QSize(200, 150)); preview->setScaledContents(true); preview->setWhatsThis(i18n("This is a screen shot of what KDM will look like.")); ml->addWidget(preview, 0, 4); info = new QLabel(this); info->setMaximumWidth(200); info->setAlignment(Qt::AlignTop); info->setWordWrap(true); info->setWhatsThis(i18n("This contains information about the selected theme.")); ml->addWidget(info, 1, 4); bInstallTheme = new QPushButton(i18nc("@action:button", "Install &new theme"), this); bInstallTheme->setWhatsThis(i18n("This will install a theme into the theme directory.")); ml->addWidget(bInstallTheme, 2, 0); bRemoveTheme = new QPushButton(i18nc("@action:button", "&Remove theme"), this); bRemoveTheme->setWhatsThis(i18n("This will remove the selected theme.")); ml->addWidget(bRemoveTheme, 2, 1); bGetNewThemes = new QPushButton(i18nc("@action:button", "&Get New Themes"), this); ml->addWidget(bGetNewThemes, 2, 2); connect(themeWidget, SIGNAL(itemSelectionChanged()), SLOT(themeSelected())); connect(bInstallTheme, SIGNAL(clicked()), SLOT(installNewTheme())); connect(bRemoveTheme, SIGNAL(clicked()), SLOT(removeSelectedThemes())); connect(bGetNewThemes, SIGNAL(clicked()), SLOT(getNewStuff())); themeDir = KStandardDirs::installPath("data") + "kdm/themes/"; defaultTheme = 0; foreach (const QString &ent, QDir(themeDir).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Unsorted)) insertTheme(themeDir + ent); }
bool TeSQLite::insertView(TeView *view) { errorMessage_ = ""; // save it's projection TeProjection* proj = view->projection(); if ( !proj || !insertProjection(proj)) { errorMessage_ = "Error inserting projection"; return false; } string sql = "INSERT INTO te_view (projection_id, name, user_name, visibility, lower_x, lower_y, upper_x, upper_y, current_theme) VALUES("; sql += Te2String(proj->id()); sql += ", '"; sql += view->name(); sql += "', '"; sql += view->user(); sql += "', "; sql += Te2String(view->isVisible()) + ", "; sql += Te2String(view->getCurrentBox().lowerLeft().x(),15) + ", "; sql += Te2String(view->getCurrentBox().lowerLeft().y(),15) + ", "; sql += Te2String(view->getCurrentBox().upperRight().x(),15) + ", "; sql += Te2String(view->getCurrentBox().upperRight().y(),15) + ", "; if(view->getCurrentTheme() == -1) sql += "null "; else sql += Te2String(view->getCurrentTheme()); sql += ")"; if(this->execute(sql)) { //int newId = getMaxValue(this, "te_view", "view_id"); int newId = getLastInsertedSerial(); if(newId >= 0) { view->id(newId); } } else return false; for(unsigned int th = 0; th < view->size(); ++th) { TeViewNode* node = view->get (th); if (node->type() == TeTHEME) { TeTheme *theme = (TeTheme*) node; insertTheme (theme); } else { TeViewTree* tree = (TeViewTree*)node; insertViewTree (tree); } } viewMap()[view->id()] = view; return true; }