bool KDesktopFile::tryExec() const { // Test for TryExec and "X-KDE-AuthorizeAction" QString te = readPathEntry("TryExec"); if(!te.isEmpty()) { if(!QDir::isRelativePath(te)) { if(::access(QFile::encodeName(te), X_OK)) return false; } else { // !!! Sergey A. Sukiyazov <*****@*****.**> !!! // Environment PATH may contain filenames in 8bit locale cpecified // encoding (Like a filenames). QStringList dirs = QStringList::split(':', QFile::decodeName(::getenv("PATH"))); QStringList::Iterator it(dirs.begin()); bool match = false; for(; it != dirs.end(); ++it) { QString fName = *it + "/" + te; if(::access(QFile::encodeName(fName), X_OK) == 0) { match = true; break; } } // didn't match at all if(!match) return false; } } QStringList list = readListEntry("X-KDE-AuthorizeAction"); if(kapp && !list.isEmpty()) { for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { if(!kapp->authorize((*it).stripWhiteSpace())) return false; } } // See also KService::username() bool su = readBoolEntry("X-KDE-SubstituteUID"); if(su) { QString user = readEntry("X-KDE-Username"); if(user.isEmpty()) user = ::getenv("ADMIN_ACCOUNT"); if(user.isEmpty()) user = "******"; if(!kapp->authorize("user/" + user)) return false; } return true; }
// return the absolute or relative path to write it to the project file QString QgsProject::writePath( QString src ) const { if ( readBoolEntry( "Paths", "/Absolute", false ) || src.isEmpty() ) { return src; } QString srcPath = src; QString projPath = fileName(); if ( projPath.isEmpty() ) { return src; } #if defined( Q_OS_WIN ) const Qt::CaseSensitivity cs = Qt::CaseInsensitive; srcPath.replace( "\\", "/" ); if ( srcPath.startsWith( "//" ) ) { // keep UNC prefix srcPath = "\\\\" + srcPath.mid( 2 ); } projPath.replace( "\\", "/" ); if ( projPath.startsWith( "//" ) ) { // keep UNC prefix projPath = "\\\\" + projPath.mid( 2 ); } #else const Qt::CaseSensitivity cs = Qt::CaseSensitive; #endif QStringList projElems = projPath.split( "/", QString::SkipEmptyParts ); QStringList srcElems = srcPath.split( "/", QString::SkipEmptyParts ); // remove project file element projElems.removeLast(); projElems.removeAll( "." ); srcElems.removeAll( "." ); // remove common part int n = 0; while ( srcElems.size() > 0 && projElems.size() > 0 && srcElems[0].compare( projElems[0], cs ) == 0 ) { srcElems.removeFirst(); projElems.removeFirst(); n++; } if ( n == 0 ) { // no common parts; might not even by a file return src; } if ( projElems.size() > 0 ) { // go up to the common directory for ( int i = 0; i < projElems.size(); i++ ) { srcElems.insert( 0, ".." ); } } else { // let it start with . nevertheless, // so relative path always start with either ./ or ../ srcElems.insert( 0, "." ); } return srcElems.join( "/" ); }
// return the absolute path from a filename read from project file QString QgsProject::readPath( QString src ) const { if ( readBoolEntry( "Paths", "/Absolute", false ) ) { return src; } // relative path should always start with ./ or ../ if ( !src.startsWith( "./" ) && !src.startsWith( "../" ) ) { #if defined(Q_OS_WIN) if ( src.startsWith( "\\\\" ) || src.startsWith( "//" ) || ( src[0].isLetter() && src[1] == ':' ) ) { // UNC or absolute path return src; } #else if ( src[0] == '/' ) { // absolute path return src; } #endif // so this one isn't absolute, but also doesn't start // with ./ or ../. // That means that it was saved with an earlier version of "relative path support", // where the source file had to exist and only the project directory was stripped // from the filename. QString home = homePath(); if ( home.isNull() ) return src; QFileInfo fi( home + "/" + src ); if ( !fi.exists() ) { return src; } else { return fi.canonicalFilePath(); } } QString srcPath = src; QString projPath = fileName(); if ( projPath.isEmpty() ) { return src; } #if defined(Q_OS_WIN) srcPath.replace( "\\", "/" ); projPath.replace( "\\", "/" ); bool uncPath = projPath.startsWith( "//" ); #endif QStringList srcElems = srcPath.split( "/", QString::SkipEmptyParts ); QStringList projElems = projPath.split( "/", QString::SkipEmptyParts ); #if defined(Q_OS_WIN) if ( uncPath ) { projElems.insert( 0, "" ); projElems.insert( 0, "" ); } #endif // remove project file element projElems.removeLast(); // append source path elements projElems << srcElems; projElems.removeAll( "." ); // resolve .. int pos; while (( pos = projElems.indexOf( ".." ) ) > 0 ) { // remove preceding element and .. projElems.removeAt( pos - 1 ); projElems.removeAt( pos - 1 ); } #if !defined(Q_OS_WIN) // make path absolute projElems.prepend( "" ); #endif return projElems.join( "/" ); }
bool ValueMap::readEntry (const QString& s, bool bDefault ){ return readBoolEntry(s,bDefault); }
KexiCSVExportWizard::KexiCSVExportWizard(const KexiCSVExport::Options& options, QWidget * parent) : K3Wizard(parent) , m_options(options) // , m_mode(mode) // , m_itemId(itemId) , m_fileSavePage(0) , m_defaultsBtn(0) , m_importExportGroup(KGlobal::config()->group("ImportExport")) , m_rowCount(-1) , m_rowCountDetermined(false) , m_cancelled(false) { if (m_options.mode == KexiCSVExport::Clipboard) { finishButton()->setText(i18n("Copy")); backButton()->hide(); } else { finishButton()->setText(i18n("Export")); } helpButton()->hide(); QString infoLblFromText; KexiGUIMessageHandler msgh(this); m_tableOrQuery = new KexiDB::TableOrQuerySchema( KexiMainWindowIface::global()->project()->dbConnection(), m_options.itemId); if (m_tableOrQuery->table()) { if (m_options.mode == KexiCSVExport::Clipboard) { setWindowTitle(i18n("Copy Data From Table to Clipboard")); infoLblFromText = i18n("Copying data from table:"); } else { setWindowTitle(i18n("Export Data From Table to CSV File")); infoLblFromText = i18n("Exporting data from table:"); } } else if (m_tableOrQuery->query()) { if (m_options.mode == KexiCSVExport::Clipboard) { setWindowTitle(i18n("Copy Data From Query to Clipboard")); infoLblFromText = i18n("Copying data from table:"); } else { setWindowTitle(i18n("Export Data From Query to CSV File")); infoLblFromText = i18n("Exporting data from query:"); } } else { msgh.showErrorMessage(KexiMainWindowIface::global()->project()->dbConnection(), i18n("Could not open data for exporting.")); m_cancelled = true; return; } // OK, source data found. // Setup pages // 1. File Save Page if (m_options.mode == KexiCSVExport::File) { m_fileSavePage = new KexiStartupFileWidget( KUrl("kfiledialog:///CSVImportExport"), //startDir KexiStartupFileWidget::Custom | KexiStartupFileWidget::SavingFileBasedDB, this); m_fileSavePage->setObjectName("m_fileSavePage"); m_fileSavePage->setMinimumHeight(kapp->desktop()->availableGeometry().height() / 2); m_fileSavePage->setAdditionalFilters(csvMimeTypes().toSet()); m_fileSavePage->setDefaultExtension("csv"); m_fileSavePage->setLocationText( KexiUtils::stringToFileName(m_tableOrQuery->captionOrName())); connect(m_fileSavePage, SIGNAL(rejected()), this, SLOT(reject())); addPage(m_fileSavePage, i18n("Enter Name of File You Want to Save Data To")); } // 2. Export options m_exportOptionsPage = new QWidget(this); m_exportOptionsPage->setObjectName("m_exportOptionsPage"); QGridLayout *exportOptionsLyr = new QGridLayout(m_exportOptionsPage); exportOptionsLyr->setObjectName("exportOptionsLyr"); m_infoLblFrom = new KexiCSVInfoLabel(infoLblFromText, m_exportOptionsPage); KexiPart::Info *partInfo = Kexi::partManager().infoForClass( QString("org.kexi-project.%1").arg(m_tableOrQuery->table() ? "table" : "query")); if (partInfo) m_infoLblFrom->setIcon(partInfo->itemIcon()); m_infoLblFrom->separator()->hide(); exportOptionsLyr->addWidget(m_infoLblFrom, 0, 0, 0, 2); m_infoLblTo = new KexiCSVInfoLabel( (m_options.mode == KexiCSVExport::File) ? i18n("To CSV file:") : i18n("To clipboard:"), m_exportOptionsPage ); if (m_options.mode == KexiCSVExport::Clipboard) m_infoLblTo->setIcon("edit-paste"); exportOptionsLyr->addWidget(m_infoLblTo, 1, 0, 1, 3); m_showOptionsButton = new KPushButton(KGuiItem(i18n("Show Options >>"), "configure"), m_exportOptionsPage); connect(m_showOptionsButton, SIGNAL(clicked()), this, SLOT(slotShowOptionsButtonClicked())); exportOptionsLyr->addWidget(m_showOptionsButton, 2, 2, 0, 0); m_showOptionsButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // -<options section> m_exportOptionsSection = new Q3GroupBox(1, Qt::Vertical, i18n("Options"), m_exportOptionsPage); m_exportOptionsSection->setObjectName("m_exportOptionsSection"); m_exportOptionsSection->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); exportOptionsLyr->addWidget(m_exportOptionsSection, 3, 3, 0, 1); QWidget *exportOptionsSectionWidget = new QWidget(m_exportOptionsSection); exportOptionsSectionWidget->setObjectName("exportOptionsSectionWidget"); QGridLayout *exportOptionsSectionLyr = new QGridLayout(exportOptionsSectionWidget); exportOptionsLyr->setObjectName("exportOptionsLyr"); // -delimiter m_delimiterWidget = new KexiCSVDelimiterWidget(false, //!lineEditOnBottom exportOptionsSectionWidget); m_delimiterWidget->setDelimiter(defaultDelimiter()); exportOptionsSectionLyr->addWidget(m_delimiterWidget, 0, 1); QLabel *delimiterLabel = new QLabel(i18n("Delimiter:"), exportOptionsSectionWidget); delimiterLabel->setBuddy(m_delimiterWidget); exportOptionsSectionLyr->addWidget(delimiterLabel, 0, 0); // -text quote QWidget *textQuoteWidget = new QWidget(exportOptionsSectionWidget); QHBoxLayout *textQuoteLyr = new QHBoxLayout(textQuoteWidget); exportOptionsSectionLyr->addWidget(textQuoteWidget, 1, 1); m_textQuote = new KexiCSVTextQuoteComboBox(textQuoteWidget); m_textQuote->setTextQuote(defaultTextQuote()); textQuoteLyr->addWidget(m_textQuote); textQuoteLyr->addStretch(0); QLabel *textQuoteLabel = new QLabel(i18n("Text quote:"), exportOptionsSectionWidget); textQuoteLabel->setBuddy(m_textQuote); exportOptionsSectionLyr->addWidget(textQuoteLabel, 1, 0); // - character encoding m_characterEncodingCombo = new KexiCharacterEncodingComboBox(exportOptionsSectionWidget); m_characterEncodingCombo->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); exportOptionsSectionLyr->addWidget(m_characterEncodingCombo, 2, 1); QLabel *characterEncodingLabel = new QLabel(i18n("Text encoding:"), exportOptionsSectionWidget); characterEncodingLabel->setBuddy(m_characterEncodingCombo); exportOptionsSectionLyr->addWidget(characterEncodingLabel, 2, 0); // - checkboxes m_addColumnNamesCheckBox = new QCheckBox(i18n("Add column names as the first row"), exportOptionsSectionWidget); m_addColumnNamesCheckBox->setChecked(true); exportOptionsSectionLyr->addWidget(m_addColumnNamesCheckBox, 3, 1); //! @todo 1.1: for copying use "Always use above options for copying" string m_alwaysUseCheckBox = new QCheckBox(i18n("Always use above options for exporting"), m_exportOptionsPage); exportOptionsLyr->addWidget(m_alwaysUseCheckBox, 4, 4, 0, 1); // exportOptionsSectionLyr->addWidget( m_alwaysUseCheckBox, 4, 1 ); m_exportOptionsSection->hide(); m_alwaysUseCheckBox->hide(); // -</options section> // exportOptionsLyr->setColumnStretch(3, 1); exportOptionsLyr->addItem( new QSpacerItem(0, 0, QSizePolicy::Preferred, QSizePolicy::MinimumExpanding), 5, 0, 1, 2); // addPage(m_exportOptionsPage, i18n("Set Export Options")); addPage(m_exportOptionsPage, m_options.mode == KexiCSVExport::Clipboard ? i18n("Copying") : i18n("Exporting")); setFinishEnabled(m_exportOptionsPage, true); // load settings if (m_options.mode != KexiCSVExport::Clipboard && readBoolEntry("ShowOptionsInCSVExportDialog", false)) { show(); slotShowOptionsButtonClicked(); } if (readBoolEntry("StoreOptionsForCSVExportDialog", false)) { // load defaults: m_alwaysUseCheckBox->setChecked(true); QString s = readEntry("DefaultDelimiterForExportingCSVFiles", defaultDelimiter()); if (!s.isEmpty()) m_delimiterWidget->setDelimiter(s); s = readEntry("DefaultTextQuoteForExportingCSVFiles", defaultTextQuote()); m_textQuote->setTextQuote(s); //will be invaliudated here, so not a problem s = readEntry("DefaultEncodingForExportingCSVFiles"); if (!s.isEmpty()) m_characterEncodingCombo->setSelectedEncoding(s); m_addColumnNamesCheckBox->setChecked( readBoolEntry("AddColumnNamesForExportingCSVFiles", true)); } updateGeometry(); // -keep widths equal on page #2: int width = qMax(m_infoLblFrom->leftLabel()->sizeHint().width(), m_infoLblTo->leftLabel()->sizeHint().width()); m_infoLblFrom->leftLabel()->setFixedWidth(width); m_infoLblTo->leftLabel()->setFixedWidth(width); }
void dvbcut_settings::load_settings() { int version = readNumEntry("/version", 0); if (version >= 1) { // config format version 1 or later beginGroup("/wheel"); wheel_increments[WHEEL_INCR_NORMAL] = readNumEntry("/incr_normal", 25*60); wheel_increments[WHEEL_INCR_SHIFT] = readNumEntry("/incr_shift", 25); wheel_increments[WHEEL_INCR_CTRL] = readNumEntry("/incr_ctrl", 1); wheel_increments[WHEEL_INCR_ALT] = readNumEntry("/incr_alt", 15*25*60); wheel_threshold = readNumEntry("/threshold", 24); // Note: delta is a multiple of 120 (see Qt documentation) wheel_delta = readNumEntry("/delta", 120); if (wheel_delta == 0) wheel_delta = 1; // avoid devide by zero endGroup(); // wheel beginGroup("/slider"); jog_maximum = readNumEntry("/jog_maximum", 180000); jog_threshold = readNumEntry("/jog_threshold", 50); // to increase the "zero frames"-region of the jog-slider jog_offset = readDoubleEntry("/jog_offset", 0.4); // sub-intervals of jog_maximum jog_interval = readNumEntry("/jog_interval", 1); if (jog_interval < 0) jog_interval = 0; lin_interval = readNumEntry("/lin_interval", 3600); if (lin_interval < 0) lin_interval = 0; endGroup(); // slider beginGroup("/lastdir"); lastdir = readEntry("/name", ""); lastdir_update = readBoolEntry("/update", true); endGroup(); // lastdir } else { // old (unnumbered) config format wheel_increments[WHEEL_INCR_NORMAL] = readNumEntry("/wheel_incr_normal", 25*60); wheel_increments[WHEEL_INCR_SHIFT] = readNumEntry("/wheel_incr_shift", 25); wheel_increments[WHEEL_INCR_CTRL] = readNumEntry("/wheel_incr_ctrl", 1); wheel_increments[WHEEL_INCR_ALT] = readNumEntry("/wheel_incr_alt", 15*25*60); wheel_threshold = readNumEntry("/wheel_threshold", 24); // Note: delta is a multiple of 120 (see Qt documentation) wheel_delta = readNumEntry("/wheel_delta", 120); if (wheel_delta == 0) wheel_delta = 1; // avoid devide by zero jog_maximum = readNumEntry("/jog_maximum", 180000); jog_threshold = readNumEntry("/jog_threshold", 50); // to increase the "zero frames"-region of the jog-slider jog_offset = readDoubleEntry("/jog_offset", 0.4); // sub-intervals of jog_maximum jog_interval = readNumEntry("/jog_interval", 1); if (jog_interval < 0) jog_interval = 0; lin_interval = readNumEntry("/lin_interval", 3600); if (lin_interval < 0) lin_interval = 0; lastdir = readEntry("/lastdir", ""); lastdir_update = true; // remove old-style entries remove("/wheel_incr_normal"); remove("/wheel_incr_shift"); remove("/wheel_incr_ctrl"); remove("/wheel_incr_alt"); remove("/wheel_threshold"); remove("/wheel_delta"); remove("/jog_maximum"); remove("/jog_threshold"); remove("/jog_offset"); remove("/jog_interval"); remove("/lin_interval"); remove("/lastdir"); remove("/idxfilter"); remove("/prjfilter"); remove("/loadfilter"); } if (version >= 2) { /* float view scale factor */ beginGroup("/viewscalefactor"); viewscalefactor = readNumEntry("/current", 1); viewscalefactor_custom = readDoubleEntry("/custom", 3.0); endGroup(); // viewscalefactor } else { viewscalefactor = readNumEntry("/viewscalefactor", 1); viewscalefactor_custom = 3.0; remove("/viewscalefactor"); } export_format = readNumEntry("/export_format", 0); beginGroup("/recentfiles"); recentfiles_max = readNumEntry("/max", 5); recentfiles.clear(); std::list<std::string> filenames; QStringList keys = childKeys(); for (unsigned int i = 0; i < recentfiles_max; ++i) { QString key = "/" + QString::number(i); if (version < 1 && keys.size()>1) { // OLD format (2 keys per input file, NO subkeys!) QString filename = readEntry(key); if (filename.isEmpty()) continue; filenames.clear(); filenames.push_back(filename.toStdString()); QString idxfilename = readEntry(key + "-idx", ""); recentfiles.push_back( std::pair<std::list<std::string>,std::string>(filenames, idxfilename.toStdString())); } else { // NEW format with subkeys and multiple files! beginGroup(key); QString filename = readEntry("/0"); if (!filename.isEmpty()) { // multiple input files? int j=0; filenames.clear(); while(!filename.isEmpty()) { filenames.push_back(filename.toStdString()); filename = readEntry("/" + QString::number(++j), ""); } QString idxfilename = readEntry("/idx", ""); recentfiles.push_back( std::pair<std::list<std::string>,std::string>(filenames, idxfilename.toStdString())); } endGroup(); // key } } endGroup(); // recentfiles start_bof = readBoolEntry("/start_bof", true); stop_eof = readBoolEntry("/stop_eof", true); beginGroup("/snapshots"); snapshot_type = readEntry("/type", "PNG"); snapshot_quality = readNumEntry("/quality", -1); snapshot_prefix = readEntry("/prefix", ""); snapshot_delimiter = readEntry("/delimiter", "_"); snapshot_first = readNumEntry("/first", 1); snapshot_width = readNumEntry("/width", 3); snapshot_extension = readEntry("/extension", "png"); snapshot_range = readNumEntry("/range", 0); snapshot_samples = readNumEntry("/samples", 1); endGroup(); // snapshots beginGroup("/pipe"); pipe_command.clear(); pipe_post.clear(); pipe_label.clear(); pipe_format.clear(); beginGroup("/0"); QString command = readEntry("/command", DVBCUT_DEFAULT_PIPE_COMMAND); QString post = readEntry("/post", DVBCUT_DEFAULT_PIPE_POST); QString label = readEntry("/label", DVBCUT_DEFAULT_PIPE_LABEL); int format = readNumEntry("/format", DVBCUT_DEFAULT_PIPE_FORMAT); endGroup(); // 0 unsigned int i = 0; while(!command.isEmpty() && !label.isEmpty()) { if(format<0 || format>3) format = 0; pipe_command.push_back(command); pipe_post.push_back(post); pipe_label.push_back(label); pipe_format.push_back(format); QString key = "/" + QString::number(++i); beginGroup(key); command = readEntry("/command",""); post = readEntry("/post",""); label = readEntry("/label",""); format = readNumEntry("/format", 0); endGroup(); // key } endGroup(); // pipe beginGroup("/chapters"); // length (>0) or number (<0) of chapter(s) chapter_interval = readNumEntry("/interval", 600*25); // detection of scene changes is rather time comsuming... //chapter_tolerance = readNumEntry("/tolerance", 10*25); //... better switch it off per default! chapter_tolerance = readNumEntry("/tolerance", 0); // average color distance needed for a scene change chapter_threshold = readDoubleEntry("/threshold", 50.); // minimal length of a chapter chapter_minimum = readNumEntry("/minimum", 200*25); endGroup(); // auto chapters }
bool KConfigBase::readBoolEntry(const QString &pKey, bool bDefault) const { return readBoolEntry(pKey.utf8().data(), bDefault); }
QVariant KConfigBase::readPropertyEntry(const char *pKey, const QVariant &aDefault) const { if(!hasKey(pKey)) return aDefault; QVariant tmp = aDefault; switch(aDefault.type()) { case QVariant::Invalid: return QVariant(); case QVariant::String: return QVariant(readEntry(pKey, aDefault.toString())); case QVariant::StringList: return QVariant(readListEntry(pKey)); case QVariant::List: { QStringList strList = readListEntry(pKey); QStringList::ConstIterator it = strList.begin(); QStringList::ConstIterator end = strList.end(); QValueList< QVariant > list; for(; it != end; ++it) { tmp = *it; list.append(tmp); } return QVariant(list); } case QVariant::Font: return QVariant(readFontEntry(pKey, &tmp.asFont())); case QVariant::Point: return QVariant(readPointEntry(pKey, &tmp.asPoint())); case QVariant::Rect: return QVariant(readRectEntry(pKey, &tmp.asRect())); case QVariant::Size: return QVariant(readSizeEntry(pKey, &tmp.asSize())); case QVariant::Color: return QVariant(readColorEntry(pKey, &tmp.asColor())); case QVariant::Int: return QVariant(readNumEntry(pKey, aDefault.toInt())); case QVariant::UInt: return QVariant(readUnsignedNumEntry(pKey, aDefault.toUInt())); case QVariant::LongLong: return QVariant(readNum64Entry(pKey, aDefault.toLongLong())); case QVariant::ULongLong: return QVariant(readUnsignedNum64Entry(pKey, aDefault.toULongLong())); case QVariant::Bool: return QVariant(readBoolEntry(pKey, aDefault.toBool()), 0); case QVariant::Double: return QVariant(readDoubleNumEntry(pKey, aDefault.toDouble())); case QVariant::DateTime: return QVariant(readDateTimeEntry(pKey, &tmp.asDateTime())); case QVariant::Date: return QVariant(readDateTimeEntry(pKey, &tmp.asDateTime()).date()); case QVariant::Pixmap: case QVariant::Image: case QVariant::Brush: case QVariant::Palette: case QVariant::ColorGroup: case QVariant::Map: case QVariant::IconSet: case QVariant::CString: case QVariant::PointArray: case QVariant::Region: case QVariant::Bitmap: case QVariant::Cursor: case QVariant::SizePolicy: case QVariant::Time: case QVariant::ByteArray: case QVariant::BitArray: case QVariant::KeySequence: case QVariant::Pen: break; } Q_ASSERT(0); return QVariant(); }