/** * Loads the application options. * Loads the options from $HOME/.qfsm/qfsmrc into @a opt. */ int FileIO::loadOptions(Options* opt) { int result=0; QDir dir = QDir::home(); QMap<QString, QString> _map; QString key, value; #ifdef WIN32 QFile file(dir.absPath()+"/Application Data/qfsm/qfsmrc"); #else QFile file(dir.absPath()+"/.qfsm/qfsmrc"); #endif if (!file.open(QIODevice::ReadOnly)) { qDebug("options not loaded"); return 1; } Q3TextStream fin(&file); fin >> key >> value; while (!fin.eof()) { _map.insert(key, value); fin >> key >> value; if (value==getEmptyFieldString()) value=""; } setOptions(&_map, opt); return result; }
void CodeManager::createDirectory(const QDir &path) { if (!path.exists()) { if (!path.mkdir(path.absPath())) { throw PoaException (QString(qApp->translate("codemanager","Could not create directory: %1")).arg(path.absPath())); } } }
void QtFileIconView::readDir( const QDir &dir ) { if ( !dir.isReadable() ) return; if ( isRoot( dir.absPath() ) ) emit disableUp(); else emit enableUp(); clear(); emit directoryChanged( dir.absPath() ); const QFileInfoList *filist = dir.entryInfoList( QDir::DefaultFilter, QDir::DirsFirst | QDir::Name ); emit startReadDir( filist->count() ); QFileInfoListIterator it( *filist ); QFileInfo *fi; bool allowRename = FALSE, allowRenameSet = FALSE; while ( ( fi = it.current() ) != 0 ) { ++it; if ( fi && fi->fileName() == ".." && ( fi->dirPath() == "/" || fi->dirPath().isEmpty() ) ) continue; emit readNextDir(); QtFileIconViewItem *item = new QtFileIconViewItem( this, new QFileInfo( *fi ) ); if ( fi->isDir() ) item->setKey( QString( "000000%1" ).arg( fi->fileName() ) ); else item->setKey( fi->fileName() ); if ( !allowRenameSet ) { if ( !QFileInfo( fi->absFilePath() ).isWritable() || item->text() == "." || item->text() == ".." ) allowRename = FALSE; else allowRename = TRUE; if ( item->text() == "." || item->text() == ".." ) allowRenameSet = FALSE; else allowRenameSet = TRUE; } item->setRenameEnabled( allowRename ); } if ( !QFileInfo( dir.absPath() ).isWritable() ) emit disableMkdir(); else emit enableMkdir(); emit readDirDone(); }
void PMenu::copyLnkFiles(QDir base_dir) { PMenuItem *item; for( item = list.first(); item != 0; item = list.next() ) { if( item->entry_type == submenu ) { QDir sub_dir(base_dir); if( item->old_name.isEmpty() ) { if( item->real_name.isEmpty() ) item->real_name = item->text_name; base_dir.mkdir(item->real_name); if( !sub_dir.cd(item->real_name) ) continue; } else { if( !base_dir.exists( item->old_name ) ) { base_dir.mkdir(item->old_name); if( base_dir.exists( item->dir_path + '/' + item->old_name + "/.directory") ) copyFiles( item->dir_path + '/' + item->old_name + "/.directory", base_dir.absPath() + '/' + item->old_name + "/.directory" ); } if( !sub_dir.cd(item->old_name) ) continue; } item->sub_menu->copyLnkFiles( sub_dir ); } } for( item = list.first(); item != 0; item = list.next() ) { if( item->entry_type == separator || item->old_name.isEmpty() ) continue; if( item->entry_type != submenu ) { if( base_dir.exists( item->old_name ) ) continue; else { if( base_dir.exists( item->dir_path + '/' + item->old_name ) ) copyFiles( item->dir_path + '/' + item->old_name, base_dir.absPath() + '/' + item->old_name ); } } } }
QStringList KStandardDirs::findDirs( const char *type, const QString& reldir ) const { QDir testdir; QStringList list; if (!QDir::isRelativePath(reldir)) { testdir.setPath(reldir); if (testdir.exists()) { if (reldir.endsWith("/")) list.append(reldir); else list.append(reldir+'/'); } return list; } checkConfig(); if (d && d->restrictionsActive && (strcmp(type, "data")==0)) applyDataRestrictions(reldir); QStringList candidates = resourceDirs(type); for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); ++it) { testdir.setPath(*it + reldir); if (testdir.exists()) list.append(testdir.absPath() + '/'); } return list; }
void Engine::save() throw(PersistingException*) { tracer->invoked(__func__); if (m_dirty) { tracer->sdebug(__func__) << "engine is dirty --> saving it..." << endl; // rename current file QDir path = m_fileAlbum->dirPath(true); QString oldFileName = m_fileAlbum->fileName(); // create new filename QString basename = QFileInfo(oldFileName).baseName(true); QString timestamp = QDateTime::currentDateTime().toString("yyyyMMdd-hhmmsszzz"); QString newFileName = QString("%1-%2.%3").arg(basename).arg(timestamp).arg(Constants::FILE_EXTENSION); tracer->sdebug(__func__) << "backing up file in directory '" << path.absPath() << "': '" << oldFileName << "' --> '" << newFileName << "'..." << endl; if (!path.rename(oldFileName, newFileName, false)) { QString msg = QString("Could not move old file '%1/%2' to '%3/%4'. Not saving file. Use 'Save As'.").arg(path.absPath()).arg(oldFileName).arg(path.absPath()).arg(newFileName); throw new PersistingException( msg, "" ); } // save XmlWriter writer = XmlWriter(*this); writer.store(new QFile(m_fileAlbum->absFilePath())); } m_dirty = false; }
/** * Recursively scans a directory for a files matching the current filter. * @param dir A directory object set to the folder from which files are * added * @return The total number of files added */ int DirScanner::scanDir(QDir& dir) { QString sCanon; QStringList slDirFiles, slDirs; QStringList::const_iterator itr; QString sFile; int nFiles = 0; if (m_bCancel) return -1; // Make sure this directory has not been previously visited (e.g., through a // symbolic link) sCanon = dir.canonicalPath(); if (m_setScanned.exists(sCanon)) return 0; m_setScanned.insert(sCanon); // Add all files in this directory slDirFiles = dir.entryList(m_sNameFilter, QDir::Files); for (itr = slDirFiles.begin(); itr != slDirFiles.end(); ++itr) { sFile = dir.absPath() + "/" + *itr; // Make sure an entry for this file does not exist if (m_pDicFiles->find(sFile) == NULL) { m_slFiles.append(sFile); nFiles++; } } QApplication::postEvent(m_pEventReceiver, new DirScanEvent(nFiles, false)); // Recurse into sub-directories, if requested if (!m_bRecursive) return nFiles; slDirs = dir.entryList(QDir::Dirs); // Iterate the list of sub-directories for (itr = slDirs.begin(); itr != slDirs.end(); ++itr) { if (m_bCancel) return -1; // Skip the "." and ".." directories if (*itr == "." || *itr == "..") continue; // Add the files in each sub-directory QDir dirSub(dir); if (dirSub.cd(*itr)) nFiles += scanDir(dirSub); } return nFiles; }
void SkyBackgroundPluginForm::on_Preset3_4PushButton_clicked() { QDir dir = skyDir; dir.cd(presetDirs[2].path()); dir.cd("19"); setupSkyBackground(dir, zUpCheckBox->isChecked()); directoryLineEdit->setText(dir.absPath()); enableCheckBox->setChecked(true); }
void SkyBackgroundPluginForm::on_Preset2_2PushButton_clicked() { QDir dir = skyDir; //dir.cd(presetDirs[1].path()); dir.cd("CloudyEvening_1024"); setupSkyBackground(dir, zUpCheckBox->isChecked()); directoryLineEdit->setText(dir.absPath()); enableCheckBox->setChecked(true); }
void PMenuItem::writeConfig( QDir dir ) { if( read_only || entry_type == separator ) return; QString file = dir.absPath(); dir_path = file.copy(); file += ( (QString) "/" + real_name ); //+ ".kdelnk" ); QFile config(file); if( !config.open(IO_ReadWrite) ) return; config.close(); KConfig kconfig(file); kconfig.setGroup("KDE Desktop Entry"); kconfig.writeEntry("Comment", comment, TRUE, FALSE, TRUE ); kconfig.writeEntry("Icon", big_pixmap_name ); kconfig.writeEntry("MiniIcon", pixmap_name ); kconfig.writeEntry("Name", text_name, TRUE, FALSE, TRUE ); switch( (int) entry_type ) { case (int) swallow_com: kconfig.writeEntry("SwallowExec", swallow_exec ); kconfig.writeEntry("SwallowTitle", swallow_title ); //break; case (int) unix_com: if( entry_type == unix_com ) { kconfig.writeEntry("SwallowExec", "" ); kconfig.writeEntry("TerminalOptions", term_opt ); } kconfig.writeEntry("Exec", command_name ); kconfig.writeEntry("Path", exec_path ); if( use_term ) kconfig.writeEntry("Terminal", 1 ); else kconfig.writeEntry("Terminal", 0 ); kconfig.writeEntry("BinaryPattern", pattern); kconfig.writeEntry("Protocols", protocols); kconfig.writeEntry("MimeType", extensions); kconfig.writeEntry("Type", "Application"); break; case (int) url: kconfig.writeEntry("URL", url_name); kconfig.writeEntry("Type", "Link"); break; case (int) device: kconfig.writeEntry("Dev", dev_name); kconfig.writeEntry("MountPoint", mount_point); kconfig.writeEntry("FSType", fs_type); kconfig.writeEntry("UnmountIcon", umount_pixmap_name); kconfig.writeEntry("ReadOnly", dev_read_only); kconfig.writeEntry("Type", "FSDevice"); break; }; kconfig.sync(); }
void KJotsMain::createFolder() { AskFileName *ask = new AskFileName(this); if( ask->exec() == QDialog::Rejected ) return; QString name = ask->getName(); delete ask; if( folder_list.contains(name) ) { QMessageBox::message(klocale->translate("Warning"), klocale->translate("A book with this name already exists."), klocale->translate("OK"), this); return; } saveFolder(); entrylist.clear(); folderOpen = TRUE; me_text->setEnabled(TRUE); le_subject->setEnabled(TRUE); me_text->setFocus(); me_text->clear(); me_text->deselect(); TextEntry *new_entry = new TextEntry; entrylist.append(new_entry); new_entry->subject = ""; current = 0; s_bar->setRange(0,0); s_bar->setValue(0); emit folderChanged(&entrylist); emit entryMoved(current); le_subject->setText(entrylist.first()->subject); folder_list.append(name); if( folders->text(folders->idAt(0)) == 0 ) folders->removeItemAt(0); folders->insertItem(name, unique_id++); //QDir dir = QDir::home(); //dir.cd(".kde/share/apps/kjots"); QDir dir = QDir( KApplication::localkdedir().data() ); dir.cd("share/apps/kjots"); current_folder_name = dir.absPath(); current_folder_name += '/'; current_folder_name += name; KConfig *config = KApplication::getKApplication()->getConfig(); config->setGroup("kjots"); config->writeEntry( "Folders", folder_list ); config->sync(); l_folder->setText(name); QPushButton *but; for( but = button_list.first(); but != 0; but = button_list.next() ) but->setOn(FALSE); }
void RubySupportPart::slotSwitchToView() { KParts::Part *activePart = partController()->activePart(); if (!activePart) return; KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart*>(activePart); if (!ropart) return; QFileInfo file(ropart->url().path()); if (!file.exists()) return; QString ext = file.extension(); QString name = file.baseName(); QString switchTo = ""; if (ext == "rjs" || ext == "rxml" || ext == "rhtml" || ext == "js.rjs" || ext == "xml.builder" || ext == "html.erb") { //this is a view already, let's show the list of all views for this model switchTo = file.dir().dirName(); } else if (ext == "rb") switchTo = name.remove(QRegExp("_controller$")).remove(QRegExp("_controller_test$")).remove(QRegExp("_test$")); if (switchTo.isEmpty()) return; if (switchTo.endsWith("s")) switchTo = switchTo.mid(0, switchTo.length() - 1); KURL::List urls; QDir viewsDir; QDir viewsDirS = QDir(project()->projectDirectory() + "/app/views/" + switchTo); QDir viewsDirP = QDir(project()->projectDirectory() + "/app/views/" + switchTo + "s"); if (viewsDirS.exists()) viewsDir = viewsDirS; else if (viewsDirP.exists()) viewsDir = viewsDirP; else return; QStringList views = viewsDir.entryList(); for (QStringList::const_iterator it = views.begin(); it != views.end(); ++it) { QString viewName = *it; if ( !(viewName.endsWith("~") || viewName == "." || viewName == "..") ) urls << KURL::fromPathOrURL(viewsDir.absPath() + "/" + viewName); } KDevQuickOpen *qo = extension<KDevQuickOpen>("KDevelop/QuickOpen"); if (qo) qo->quickOpenFile(urls); }
void MainWindow::go() { Photo *photo; Image img; int num, diff, offset; QDir dir = QDir::home(); DCOPRef desktop; desktop.setRef( "kdesktop", "KBackgroundIface" ); // turns out DCOP is the easiest way dir.cd( "images" ); if (!dir.exists("flickr")) dir.mkdir("flickr"); dir.cd( "flickr" ); for (photo = photos.first(); photo; photo = photos.next()) { num = photo->desktop; if (num == 0) continue; qDebug("width: %d; height: %d; ratio: %f", photo->width, photo->height, photo->ratio); KURL destUrl( QString("file://%1/%2").arg(dir.absPath()).arg(photo->url.fileName()) ); qDebug( destUrl.url() ); qDebug( photo->url.url() ); if (KIO::NetAccess::file_copy(photo->url, destUrl, -1, false)) { img.read(destUrl.path()); if (photo->ratio < dratio) { // height needs to be changed diff = (int)roundf(photo->height - (photo->width / dratio)); offset = diff / 2; img.chop(Geometry(0, offset)); img.crop(Geometry(photo->width, photo->height - diff)); } else if (photo->ratio > dratio) { // width needs to be changed diff = (int)roundf(photo->width - (photo->height * dratio)); offset = diff / 2; img.chop(Geometry(offset, 0)); img.crop(Geometry(photo->width - diff, photo->height)); } img.scale(Geometry(dwidth, dheight)); img.write(destUrl.path()); } desktop.call( "setWallpaper", num, destUrl.path(), 1 ); } }
void myQLoader::load_module_ex(const QString& name, bool module, const QString& nameModule, const QPixmap& pix) { if(!module) { worker->clearArguments(); //add code run program QStringList str = QStringList::split(" ",name); worker->setArguments(str); if(!worker->start()); } else { QLibrary lib(name); //add code run module QSettings settings; QString ApplicationPath; // = qApp->applicationDirPath(); setAplDir(ApplicationPath); QDir d = QDir::home(); QString s1 = d.absPath(); settings.removeSearchPath( QSettings::Unix, s1+"/.qt"); settings.insertSearchPath( QSettings::Unix, s1+"/.SCT" ); QString slang = settings.readEntry("/SCT/Language_UI","en"); QTranslator myapp( 0 ); myapp.load( nameModule + "_" + slang, ApplicationPath+"/lang"); qApp->installTranslator( &myapp ); typedef void (*showW)(const QPixmap& ); showW shw = (showW)lib.resolve( "run_module" ); if ( shw ) shw(pix); else ;//QMessageBox::about(this,tr("Error"),tr("Can't load module")); lib.unload(); //qApp->removeTranslator(&myapp); } }
// --------------------------------------------------------------- int PackageDialog::extractDirectory(QFile& PkgFile, Q_UINT32 Count, QDir& currDir) { char *p = (char*)malloc(Count); PkgFile.readBlock(p, Count); if(currDir.cd(QString(p))) { // directory exists ? MsgText->append(tr("ERROR: Project directory \"%1\" already exists!").arg(QString(p))); return -1; } if(!currDir.mkdir(QString(p))) { MsgText->append(tr("ERROR: Cannot create directory \"%1\"!").arg(QString(p))); return -2; } currDir.cd(QString(p)); MsgText->append(tr("Create and enter directory \"%1\"").arg(currDir.absPath())); free(p); return 1; }
/*! convert path name into the url in the hypertext generated by htags. * \param path path name * \returns URL NULL: not found. */ QCString Htags::path2URL(const QCString &path) { QCString url,symName=path; QCString dir = g_inputDir.absPath().utf8(); int dl=dir.length(); if ((int)symName.length()>dl+1) { symName = symName.mid(dl+1); } if (!symName.isEmpty()) { QCString *result = g_symbolDict[symName]; //printf("path2URL=%s symName=%s result=%p\n",path.data(),symName.data(),result); if (result) { url = "HTML/" + *result; } } return url; }
void KJotsMain::openFolder(int id) { QPushButton *but; for( but = button_list.first(); but != NULL; but = button_list.next() ) but->setOn(FALSE); but = (QPushButton *) bg_top->find(id); if( but ) but->setOn(TRUE); //QDir dir = QDir::home(); //dir.cd(".kde/share/apps/kjots"); QDir dir = QDir( KApplication::localkdedir().data() ); dir.cd("share/apps/kjots"); QString file_name = dir.absPath(); file_name += '/'; file_name += folder_list.at( folders->indexOf(id) ); if( current_folder_name == file_name ) return; if( folderOpen ) saveFolder(); current_folder_name = file_name; if( readFile(current_folder_name) < 0) { folderOpen = FALSE; debug("Kjots: Unable to open folder"); return; } current = 0; me_text->deselect(); me_text->setText(entrylist.first()->text); emit folderChanged(&entrylist); emit entryMoved(current); le_subject->setText(entrylist.first()->subject); folderOpen = TRUE; l_folder->setText( folder_list.at(folders->indexOf(id)) ); me_text->setEnabled(TRUE); le_subject->setEnabled(TRUE); me_text->setFocus(); s_bar->setRange(0,entrylist.count()-1); s_bar->setValue(0); }
static void lookForDefinitions( const QString& dir, const QString& filter, MetaTranslator* tor, fetchFunctor fetchtr ) { QDir d ( dir ); d.setFilter( QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks ); d.setNameFilter( filter ); d.setSorting( QDir::Name ); d.setMatchAllDirs( true ); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; for ( ; ( fi = it.current() ) != 0; ++it ) { // skip "." and ".." dir if ( fi->isDir() && ( fi->fileName() == "." || fi->fileName() == ".." ) ) continue; else if ( fi->isDir() ) lookForDefinitions( d.absPath() + "/" + fi->fileName(), filter, tor, fetchtr ); else { fetchtr( dir + "/" + fi->fileName(), tor, 0, true ); } } }
void Kfm::setUpDest (QString *url) { // This function checks if destination is global mime/apps path and // if so, makes a local variant of it. It vreates all needed // directories and .directory files. It modifies dest so it can be // used with kojob or any other functions. If user is root and/or has // access to given path nothing is done. // This function is here to reduce duplication of code. It is // verbatim copy of code from kfmview's slotDropEvent. //-------- Sven's write to pseudo global mime/app dirs start --- // Consider the following case: // User opened mime/apps dir and has not any local items => // displayed are global items or global dirs with items. // Now he clicks on dir Images/. Global Images/ dir openes. Now // user wants to drag some new item he got from friend to this // dir; He can't; this is a global directory. He is frustrated. // Fix: If url contains global mime/apps path, repair it to // point to local variant; create all needed dirs too. // If user is a root or can somehow write to globals // (whole KDE installed in his home dir), also do nothing. // Most of code is from kfmprops.cpp (= tested good). #define GLOBALMIME kapp->kde_mimedir().data() #define LOCALMIME (kapp->localkdedir() + "/share/mimelnk").data() #define GLOBALAPPS kapp->kde_appsdir().data() #define LOCALAPPS (kapp->localkdedir() + "/share/applnk").data() if (KfmGui::sumode) return; QString tryPath; tryPath = url->data(); // copy (hope deep) bool specialCase = false; // Some users CAN write to GLOBAL*. if (tryPath.contains(GLOBALMIME) && // if global mime.. access (GLOBALMIME, W_OK) != 0) // ..and canot write { tryPath.remove(5, strlen(GLOBALMIME)); tryPath.insert(5, LOCALMIME); specialCase = true; } else if (tryPath.contains(GLOBALAPPS) && // if global apps.. access (GLOBALAPPS, W_OK) != 0) // ..and canot write { tryPath.remove(5, strlen(GLOBALAPPS)); tryPath.insert(5, LOCALAPPS); specialCase = true; } // Ok repaired. Now we have to check/create nedded dir(s) if (specialCase) { QString path = &(url->data())[5]; QDir lDir; // debug ("********SPECIAL CASE"); if (path.find(kapp->kde_appsdir()) == 0) // kde_appsdir on start of path { path.remove(0, strlen(kapp->kde_appsdir())); //remove kde_appsdir lDir.setPath(LOCALAPPS); } else if (path.find(kapp->kde_mimedir()) == 0) // kde_mimedir on start of path { path.remove(0, strlen(kapp->kde_mimedir())); //remove kde_appsdir lDir.setPath(LOCALMIME); } else { debug ("HEEELP"); return; } if (path[0] == '/') path.remove(0, 1); // remove / bool err; while (path.contains('/')) { int i = path.find('/'); // find separator if (!lDir.cd(path.left(i))) // exists? { lDir.mkdir((path.left(i))); // no, create if (!lDir.cd((path.left(i)))) // can cd to? { err = true; // no flag it... // debug ("Can't cd to %s in %s", path.left(i).data(), // lDir.absPath().data()); break; // and exit while } // Begin copy .directory if exists here. // This block can be commented out without problems // in case of problems. { QFile tmp(kapp->kde_appsdir() + "/" + path.left(i) + "/.directory"); //debug ("---- looking for: %s", tmp.name()); if (tmp.open( IO_ReadOnly)) { //debug ("--- opened RO"); char *buff = new char[tmp.size()+10]; if (buff != 0) { if (tmp.readBlock(buff, tmp.size()) != -1) { size_t tmpsize = tmp.size(); //debug ("--- read"); tmp.close(); tmp.setName(lDir.absPath() + "/.directory"); //debug ("---- copying to: %s", tmp.name()); if (tmp.open(IO_ReadWrite)) { //debug ("--- opened RW"); if (tmp.writeBlock(buff, tmpsize) != -1) { //debug ("--- wrote"); tmp.close(); } else { //debug ("--- removed"); tmp.remove(); } } // endif can open to write } // endif can read else //coulnd't read tmp.close(); delete[] buff; } // endif is alocated } // can open to write } // End coping .directory file } path.remove (0, i); // cded to; if (path[0] == '/') path.remove(0, 1); // remove / from path } // if it fails, kfmman will let us know url->setStr(tryPath.data()); } // end if special case //-------- Sven's write to pseudo global mime/app dirs end --- }
/** reads the configuration file .cuterc*/ void readConfig() { QDir dir = QDir::home(); if( !dir.cd(".cute") ){ dir.cd(".cute"); QFileInfo fi(dir, ".cute"); if(fi.exists()){ if(fi.isDir()) QMessageBox::warning(qApp->mainWidget(), "CUTE", "Cannot cd into .cute"); else QMessageBox::warning(qApp->mainWidget(), "CUTE", "Cannot create directory"); } else{ QMessageBox::information(qApp->mainWidget(), "CUTE", "Creating ~/.cute directory"); if(!dir.mkdir(".cute")) QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute directory"); else{ dir.cd(".cute"); if(!dir.mkdir("scripts")) QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute/scripts directory"); if(!dir.mkdir("macros")) QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute/macros directory"); if(!dir.mkdir("sessions")) QMessageBox::information(qApp->mainWidget(), "CUTE", "Could not create ~/.cute/sessions directory"); } } } // if cute version >= 0.1.6 langs dir is required if( !QDir(QDir::homeDirPath()+QDir::separator()+".cute"+QDir::separator()+"langs").exists() ) { QDir destDir = QDir::home(); destDir.cd(".cute"); destDir.mkdir("langs"); destDir.cd("langs"); QDir srcDir(LANG_DIR); QString data; QStringList dirList = srcDir.entryList(); for( int i = 2; i < dirList.count(); i++) if( QFileInfo(srcDir.absPath()+QDir::separator()+dirList[i]).isFile()) { QFile srcFile(srcDir.absPath()+QDir::separator()+dirList[i]); QFile destFile(destDir.absPath()+QDir::separator()+dirList[i]); if(destFile.exists()) continue; QTextStream destStream(&destFile); QTextStream srcStream(&srcFile); srcFile.open(IO_ReadOnly); destFile.open(IO_WriteOnly); data = srcStream.read(); destStream << data; srcFile.close(); destFile.close(); } } QFile file(QDir::homeDirPath()+"/.cuterc"); if(!file.exists()){ QMessageBox::information(qApp->mainWidget(), "CUTE", "Creating ~/.cuterc"); file.open(IO_ReadOnly); file.close(); return; } //FILE *c_file = fopen("/home/heiko/.cuterc", "r"); //PyRun_SimpleFile(c_file, ".cuterc"); QString const_cmd("execfile(\".cuterc\")\n"); dir = QDir::current(); QDir::setCurrent( QDir::homeDirPath() ); char *cmd = new char[1024]; strcpy(cmd, const_cmd.latin1()); PyRun_SimpleString(cmd); // read language config files QDir langDir = QDir(QDir::homeDirPath()+QDir::separator()+".cute"+QDir::separator()+"langs"); QStringList langEntryList = langDir.entryList(); QString langFile; for( int i = 2; i < langEntryList.count(); i++ ){ QString langFile = langDir.absPath()+QDir::separator()+langEntryList[i]; QFileInfo fi(langDir, langFile); if(fi.isFile()){ langFile = QString("execfile(\"")+langFile+QString("\")\n"); char *cmd = strdup(langFile); PyRun_SimpleString( cmd ); } } QDir::setCurrent( dir.absPath() ); }
void PMenu::writeConfig( QDir base_dir, PMenuItem *parent_item) { if( parent_item ) if( parent_item->read_only ) return; if( !base_dir.exists() ) { return; } QString name; const QStrList *temp_list = base_dir.entryList("*", QDir::Files); QStrList file_list; file_list.setAutoDelete(TRUE); QStrListIterator temp_it( *temp_list ); while( name = temp_it.current() ) { file_list.append(name); ++temp_it; } temp_list = base_dir.entryList("*", QDir::Dirs); QStrList dir_list; dir_list.setAutoDelete(TRUE); temp_it.toFirst(); while( name = temp_it.current() ) { if(name != "." && name != "..") dir_list.append(name); ++temp_it; } QString sort_order; PMenuItem *item; for( item = list.first(); item != 0; item = list.next() ) { // if( item->read_only ) // continue; if( item->entry_type == separator ) sort_order += ((QString) "SEPARATOR" + ','); else sort_order += (item->real_name + ','); if( item->getType() == submenu ) { if( !item->read_only ) { QDir sub_dir(base_dir); if( !sub_dir.cd(item->real_name) ) { base_dir.mkdir(item->real_name); if( !sub_dir.cd(item->real_name) ) continue; } item->sub_menu->writeConfig( sub_dir, item ); } dir_list.remove(item->real_name); } else { if( item->entry_type != separator ) { if( !item->read_only ) { if( item->real_name.isEmpty() ) item->real_name = uniqueFileName(item->text_name); item->writeConfig(base_dir); } file_list.remove(item->real_name); // + ".kdelnk"); } } } // remove files not in pmenu for( name = file_list.first(); name != 0; name = file_list.next() ) { if( isKdelnkFile(base_dir.absFilePath(name)) ) { //debug("will remove file: %s", (const char *) name ); base_dir.remove(name); } } // remove dirs not in pmenu for( name = dir_list.first(); name != 0; name = dir_list.next() ) { //debug("will remove dir: %s", (const char *) name ); QDir sub_dir(base_dir); if(sub_dir.cd(name)) { PMenu *new_menu = new PMenu; new_menu->writeConfig(sub_dir); delete new_menu; sub_dir.remove(".directory"); } base_dir.rmdir(name); } sort_order.truncate(sort_order.length()-1); QString file = base_dir.absPath(); file += "/.directory"; QFile config(file); if( !config.open(IO_ReadWrite) ) return; config.close(); KConfig kconfig(file); kconfig.setGroup("KDE Desktop Entry"); kconfig.writeEntry("SortOrder", sort_order); if( parent_item ) { kconfig.writeEntry("MiniIcon", parent_item->pixmap_name ); if( parent_item->big_pixmap_name.isEmpty() ) parent_item->big_pixmap_name = "folder.xpm"; kconfig.writeEntry("Icon", parent_item->big_pixmap_name ); kconfig.writeEntry("Name", parent_item->text_name, TRUE, FALSE, TRUE ); } kconfig.sync(); }
/*! \fn myQLoader::loadList() */ void myQLoader::loadList() { QSettings settings; QDir d = QDir::home(); QString s = d.absPath(); settings.insertSearchPath( QSettings::Unix, s+"/.SCT" ); //read settings QString boot1 = settings.readEntry(APP_KEY+"Boot"); QString mount = settings.readEntry(APP_KEY+"Mount"); QString keyboard1 = settings.readEntry(APP_KEY+"Keyboard"); QString sound1 = settings.readEntry(APP_KEY+"Sound",""); QString xserver1 = settings.readEntry(APP_KEY+"XServer",""); QString hwinfo1 = settings.readEntry(APP_KEY+"Hardware",""); QString printer1 = settings.readEntry(APP_KEY+"Printer",""); QString mouse1 = settings.readEntry(APP_KEY+"Mouse",""); QString scaner1 = settings.readEntry(APP_KEY+"Scaner",""); QString ftp1 = settings.readEntry(APP_KEY+"FTPSrv",""); QString Apache1 = settings.readEntry(APP_KEY+"WebSrv",""); QString nfs1 = settings.readEntry(APP_KEY+"NFS",""); QString netw1 = settings.readEntry(APP_KEY+"Network",""); QString mail1 = settings.readEntry(APP_KEY+"MailSrv",""); QString smb1 = settings.readEntry(APP_KEY+"SambaSrv",""); QString dns1 = settings.readEntry(APP_KEY+"DNSSrv",""); QString DHCP1 = settings.readEntry(APP_KEY+"DHCPSrv",""); QString proxy = settings.readEntry(APP_KEY+"ProxySrv",""); QString package1 = settings.readEntry(APP_KEY+"PackageManager",""); QString sct_rpm; // = qApp->applicationDirPath(); setAplDir(sct_rpm); sct_rpm += "/modules/rpm"; QFile fi(sct_rpm); if(!fi.exists()) sct_rpm = ""; QString user1 = settings.readEntry(APP_KEY+"Config_User",""); QString root1 = settings.readEntry(APP_KEY+"Conf_Root_Psw",""); QString servic = settings.readEntry(APP_KEY+"Conf_Service",""); QString date = settings.readEntry(APP_KEY+"Conf_Data_Time",""); QString Secur = settings.readEntry(APP_KEY+"Conf_Security",""); QString syslog = settings.readEntry(APP_KEY+"ViewLog",""); QString lang = settings.readEntry(APP_KEY+"Lang",""); myInfo_modules data; if(!boot1.isEmpty()) { data.description = tr("Configure your boot loader"); data.name = tr("boot"); data.group = tr("Boot config"); data.exec = boot1; data.module = false; data.pixModule = pixBootRedHat; addToList(data); } if(!hwinfo1.isEmpty()) { data.description = tr("Listen information of your computer"); data.name = tr("Hardware"); data.group = tr("Devices"); data.exec = hwinfo1; data.module = false; data.pixModule = pixHwBrowser; addToList(data); } if(!xserver1.isEmpty()) { data.description = tr("Configure your display"); data.name = tr("Display"); data.group = tr("Devices"); data.exec = xserver1; data.module = false; data.pixModule = pixDisplay; addToList(data); } if(!sound1.isEmpty()) { data.description = tr("Configure your sound cart"); data.name = tr("Soundcart"); data.group = tr("Devices"); data.exec = sound1; data.module = false; data.pixModule = pixSoundcard; addToList(data); } if(!keyboard1.isEmpty()) { data.description = tr("Configure your keyboard"); data.name = tr("Keyboard"); data.group = tr("Devices"); data.exec = keyboard1; data.module = false; data.pixModule = pixKeyboard; addToList(data); } if(!printer1.isEmpty()) { data.description = tr("Configure your printer"); data.name = tr("Printer"); data.group = tr("Devices"); data.exec = printer1; data.module = false; data.pixModule = pixPrinter; addToList(data); } if(!scaner1.isEmpty()) { data.description = tr("Configure your scaner"); data.name = tr("Scaner"); data.group = tr("Devices"); data.exec = scaner1; data.module = false; data.pixModule = pixScaner; addToList(data); } if(!mouse1.isEmpty()) { data.description = tr("Configure your mouse"); data.name = tr("Mouse"); data.group = tr("Devices"); data.exec = mouse1; data.module = false; data.pixModule = pixMouse; addToList(data); } if(!mount.isEmpty()) { data.description = tr("Your mount manager"); data.name = tr("Mount Points"); data.group = tr("Hard Disk"); data.exec = mount; data.module = false; data.pixModule = pixRedHatUserMount; addToList(data); } if(!netw1.isEmpty()){ data.description = tr("Configure your network"); data.name = tr("Network"); data.group = tr("Network"); data.exec = netw1; data.module = false; data.pixModule = pixNet; addToList(data); } if(!Apache1.isEmpty()){ data.description = tr("Configure Web server"); data.name = tr("Web Server"); data.group = tr("Network"); data.exec = Apache1; data.module = false; data.pixModule = pixHTTP; addToList(data); } if(!smb1.isEmpty()){ data.description = tr("Configure Samba server"); data.name = tr("Samba"); data.group = tr("Network"); data.exec = smb1; data.module = false; data.pixModule = pixSamba; addToList(data); } if(!nfs1.isEmpty()){ data.description = tr("Configure NFS server"); data.name = tr("NFS"); data.group = tr("Network"); data.exec = nfs1; data.module = false; data.pixModule = pixNFS; addToList(data); } if(!ftp1.isEmpty()){ data.description = tr("Configure FTP server"); data.name = tr("FTP"); data.group = tr("Network"); data.exec = ftp1; data.module = false; data.pixModule = pixFTP; addToList(data); } if(!mail1.isEmpty()){ data.description = tr("Configure mail in your computer"); data.name = tr("Mail"); data.group = tr("Network"); data.exec = mail1; data.module = false; data.pixModule = pixMail; addToList(data); } if(!dns1.isEmpty()){ data.description = tr("Configure DNS Server"); data.name = tr("DNS"); data.group = tr("Network"); data.exec = dns1; data.module = false; data.pixModule = pixDNS; addToList(data); } if(!DHCP1.isEmpty()){ data.description = tr("Configure DHCP Server"); data.name = tr("DHCP"); data.group = tr("Network"); data.exec = DHCP1; data.module = false; data.pixModule = pixDHCP; addToList(data); } if(!proxy.isEmpty()){ data.description = tr("Configure Proxy"); data.name = tr("Proxy"); data.group = tr("Network"); data.exec = proxy; data.module = false; data.pixModule = pixProxy; addToList(data); } if(!package1.isEmpty()) { data.description = tr("Your package manager"); data.name = tr("Packages"); data.group = tr("Software"); data.exec = package1; data.module = false; data.pixModule = pixPackage; addToList(data); } if(!sct_rpm.isEmpty()) { data.description = tr("(Add packages)"); data.name = tr("Add rpm"); data.group = tr("Software"); data.exec = sct_rpm+" -i"; data.module = false; data.pixModule = pixRpm_add; addToList(data); data.description = tr("(Remove packages)"); data.name = tr("Remove rpm"); data.group = tr("Software"); data.exec = sct_rpm; data.module = false; data.pixModule = pixRpm_rem; addToList(data); } if(!user1.isEmpty()){ data.description = tr("Configure users or groups in your computer"); data.name = tr("Users and Groups"); data.group = tr("System"); data.exec = user1; data.module = false; data.pixModule = pixUserConfig; addToList(data); } if(!date.isEmpty()){ data.description = tr("Configure date and time"); data.name = tr("Date and Time"); data.group = tr("System"); data.exec = date; data.module = false; data.pixModule = pixDateTime; addToList(data); } if(!syslog.isEmpty()){ data.description = tr("Listen System Log files"); data.name = tr("Sys Log"); data.group = tr("System"); data.exec = syslog; data.module = false; data.pixModule = pixSysLog; addToList(data); } if(!servic.isEmpty()){ data.description = tr("Configure Services in your Computer"); data.name = tr("Services"); data.group = tr("System"); data.exec = servic; data.module = false; data.pixModule = pixServicess; addToList(data); } if(!root1.isEmpty()){ data.description = tr("Change root password"); data.name = tr("Root Password"); data.group = tr("System"); data.exec = root1; data.module = false; data.pixModule = pixRoot; addToList(data); } if(!Secur.isEmpty()){ data.description = tr("Configure Security in your Computer"); data.name = tr("Security"); data.group = tr("System"); data.exec = Secur; data.module = false; data.pixModule = pixSequrytiLevel; addToList(data); } if(!lang.isEmpty()){ data.description = tr("Select languange in your computer"); data.name = tr("Language"); data.group = tr("System"); data.exec = lang; data.module = false; data.pixModule = pixLang; addToList(data); } }
/*! constructs command line of htags(1) and executes it. * \retval TRUE success * \retval FALSE an error has occurred. */ bool Htags::execute(const QCString &htmldir) { static QStrList &inputSource = Config_getList("INPUT"); static bool quiet = Config_getBool("QUIET"); static bool warnings = Config_getBool("WARNINGS"); static QCString htagsOptions = ""; //Config_getString("HTAGS_OPTIONS"); static QCString projectName = Config_getString("PROJECT_NAME"); static QCString projectNumber = Config_getString("PROJECT_NUMBER"); QCString cwd = QDir::currentDirPath().utf8(); if (inputSource.isEmpty()) { g_inputDir.setPath(cwd); } else if (inputSource.count()==1) { g_inputDir.setPath(inputSource.first()); if (!g_inputDir.exists()) err("Cannot find directory %s. " "Check the value of the INPUT tag in the configuration file.\n", inputSource.first() ); } else { err("If you use USE_HTAGS then INPUT should specific a single directory. \n"); return FALSE; } /* * Construct command line for htags(1). */ QCString commandLine = " -g -s -a -n "; if (!quiet) commandLine += "-v "; if (warnings) commandLine += "-w "; if (!htagsOptions.isEmpty()) { commandLine += ' '; commandLine += htagsOptions; } if (!projectName.isEmpty()) { commandLine += "-t \""; commandLine += projectName; if (!projectNumber.isEmpty()) { commandLine += '-'; commandLine += projectNumber; } commandLine += "\" "; } commandLine += " \"" + htmldir + "\""; QCString oldDir = QDir::currentDirPath().utf8(); QDir::setCurrent(g_inputDir.absPath()); //printf("CommandLine=[%s]\n",commandLine.data()); portable_sysTimerStart(); bool result=portable_system("htags",commandLine,FALSE)==0; portable_sysTimerStop(); QDir::setCurrent(oldDir); return result; }
void Scanner::scan () { if (! fileList.count() && ! allSymbols->isChecked()) { QMessageBox::information(this, tr("Qtstalker: Error"), tr("No symbols selected.")); return; } // open the CUS plugin QString iplugin("CUS"); IndicatorPlugin *plug = config.getIndicatorPlugin(iplugin); if (! plug) { config.closePlugin(iplugin); return; } QString s; list->getText(s); QStringList l = QStringList::split("\n", s, FALSE); plug->setCustomFunction(l); this->setEnabled(FALSE); // clear dir for scan symbols QDir dir; config.getData(Config::GroupPath, s); s.append("/Scanner"); if (! dir.exists(s, TRUE)) dir.mkdir(s, TRUE); s.append("/" + scannerName); if (! dir.exists(s, TRUE)) dir.mkdir(s, TRUE); else { int loop; dir.setPath(s); for (loop = 2; loop < (int) dir.count(); loop++) { QString s2 = dir.absPath() + "/" + dir[loop]; if (! dir.remove(s2, TRUE)) qDebug("%s not removed", s2.latin1()); } } if (allSymbols->isChecked()) { QString ts; if (! basePath->currentText().compare(tr("Chart"))) config.getData(Config::DataPath, ts); else config.getData(Config::GroupPath, ts); Traverse trav(Traverse::File); trav.traverse(ts); trav.getList(fileList); } QProgressDialog prog(tr("Scanning..."), tr("Cancel"), fileList.count(), this, "progress", TRUE); prog.show(); int minBars = bars->value(); emit message(QString("Scanning...")); int loop; for (loop = 0; loop < (int) fileList.count(); loop++) { prog.setProgress(loop); emit message(QString()); if (prog.wasCancelled()) { emit message(QString("Scan cancelled")); break; } QFileInfo fi(fileList[loop]); if (fi.isDir()) continue; DbPlugin db; QDir dir; if (! dir.exists(fileList[loop])) continue; db.open(fileList[loop], chartIndex); db.setBarRange(minBars); db.setBarLength((BarData::BarLength) barLengthList.findIndex(period->currentText())); BarData *recordList = new BarData(fileList[loop]); QDateTime dt = QDateTime::currentDateTime(); db.getHistory(recordList, dt); db.close(); // load the CUS plugin and calculate plug->setIndicatorInput(recordList); Indicator *i = plug->calculate(); if (! i->getLines()) { delete recordList; delete i; continue; } PlotLine *line = i->getLine(0); if (line && line->getSize() > 0) { if (line->getData(line->getSize() - 1) > 0) { QString ts; config.getData(Config::GroupPath, ts); QString s = "ln -s \"" + fileList[loop] + "\" " + ts + "/Scanner/" + scannerName; system(s); } } delete recordList; delete i; emit message(QString()); } if (! prog.wasCancelled()) emit message(QString("Scan complete")); config.closePlugin(iplugin); this->setEnabled(TRUE); emit scanComplete(); }
// ------------------------------------------------------------------------ void OctaveWindow::adjustDirectory() { sendCommand("cd \"" + QucsWorkDir.absPath() + "\""); }
void SkyBackgroundPluginForm::setupSkyBackground( const QDir dir, const bool zUp ) { try { skyBackground = NullFC; bool imageLoaded[6] = {false, false, false, false, false, false}; const QFileInfoList* fileList = dir.entryInfoList(); QFileInfoListIterator it(*fileList); QFileInfo* fileInfo; while ((fileInfo = it.current()) != 0) { QString qstr = fileInfo->absFilePath(); const char *filename = qstr.latin1(); if (((qstr.find("north") >= 0) || (qstr.find("front") >= 0)) && !imageLoaded[0]) { beginEditCP(images[5]); if (images[5]->read(filename)) { beginEditCP(textures[5]); textures[5]->setImage(images[5]); endEditCP(textures[5]); vrLog::info("Sky Background: Front/North image loaded."); imageLoaded[0] = true; } endEditCP(images[5]); } if (((qstr.find("south") >= 0) || (qstr.find("back") >= 0)) && !imageLoaded[1]) { beginEditCP(images[4]); if (images[4]->read(filename)) { if (zUp) vrImage::rotateImage180Degrees(images[4]); beginEditCP(textures[4]); textures[4]->setImage(images[4]); endEditCP(textures[4]); vrLog::info("Sky Background: Back/South image loaded."); imageLoaded[1] = true; } endEditCP(images[4]); } if (((qstr.find("down") >= 0) || (qstr.find("bottom") >= 0)) && !imageLoaded[2]) { beginEditCP(images[3]); if (images[3]->read(filename)) { beginEditCP(textures[3]); textures[3]->setImage(images[3]); endEditCP(textures[3]); vrLog::info("Sky Background: Bottom/Down image loaded."); imageLoaded[2] = true; } endEditCP(images[3]); } if (((qstr.find("up") >= 0) || (qstr.find("top") >= 0)) && !imageLoaded[3]) { beginEditCP(images[2]); if (images[2]->read(filename)) { if (zUp) vrImage::rotateImage180Degrees(images[2]); beginEditCP(textures[2]); textures[2]->setImage(images[2]); endEditCP(textures[2]); vrLog::info("Sky Background: Top/Up image loaded."); imageLoaded[3] = true; } endEditCP(images[2]); } if (((qstr.find("east") >= 0) || (qstr.find("right") >= 0)) && !imageLoaded[4]) { beginEditCP(images[1]); if (images[1]->read(filename)) { if (zUp) vrImage::rotate90Left(images[1]); beginEditCP(textures[1]); textures[1]->setImage(images[1]); endEditCP(textures[1]); vrLog::info("Sky Background: Right/East image loaded."); imageLoaded[4] = true; } endEditCP(images[1]); } if (((qstr.find("west") >= 0) || (qstr.find("left") >= 0)) && !imageLoaded[5]) { beginEditCP(images[0]); if (images[0]->read(filename)) { if (zUp) vrImage::rotate90Right(images[0]); beginEditCP(textures[0]); textures[0]->setImage(images[0]); endEditCP(textures[0]); vrLog::info("Sky Background: Left/West image loaded."); imageLoaded[5] = true; } endEditCP(images[0]); } ++it; } skyBackground = SkyBackground::create(); beginEditCP(skyBackground); if (!zUp) { skyBackground->setFrontTexture(textures[5]); skyBackground->setBackTexture(textures[4]); skyBackground->setBottomTexture(textures[3]); skyBackground->setTopTexture(textures[2]); skyBackground->setRightTexture(textures[1]); skyBackground->setLeftTexture(textures[0]); } else { skyBackground->setFrontTexture(textures[3]); skyBackground->setBackTexture(textures[2]); skyBackground->setBottomTexture(textures[4]); skyBackground->setTopTexture(textures[5]); skyBackground->setRightTexture(textures[1]); skyBackground->setLeftTexture(textures[0]); } endEditCP(skyBackground); vrOSGWidget *gl = vrOSGWidget::getMGLW(-1); ViewportPtr vredViewport = gl->getViewport(); //oldBackground = vredViewport->getBackground(); beginEditCP(vredViewport); vredViewport->setBackground(skyBackground); endEditCP(vredViewport); directoryLineEdit->setText(dir.absPath()); // read light settings if (SetLightingCheckBox->isChecked()) { string lightName = LightNameLineEdit->text().ascii(); if (!QFile::exists(dir.absPath() + "/LightSettings.xml")) vrLog::warning("Light Settings not found."); else { QFile* file = new QFile(dir.absPath() + "/LightSettings.xml"); if (file->open(IO_ReadOnly)) { LightSettingsHandler handler; QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); QXmlInputSource source(file); reader.parse(source); file->close(); handler.direction.normalize(); vector<NodePtr> lights; vrLights::getLights(lights); bool lightSet = false; for (vector<NodePtr>::const_iterator it = lights.begin(); it != lights.end(); ++it) { LightPtr light = LightPtr::dcast((*it)->getCore()); if (light != NullFC) { NodePtr node = *it; string name = getName(node); if (name.find(lightName) != string::npos) { setLightSettings(light, handler); lightSet = true; } } } if (!lightSet) { NodePtr rootNode = vrScenegraph::getRoot(); TransformPtr beaconTransform = Transform::create(); NodePtr beaconNode = Node::create(); beginEditCP(beaconNode); beaconNode->setCore(beaconTransform); endEditCP(beaconNode); PointLightPtr light = PointLight::create(); beginEditCP(light); light->setAttenuation(1,0,0); light->setBeacon(beaconNode); endEditCP(light); NodePtr lightNode = Node::create(); beginEditCP(lightNode); lightNode->setCore(light); endEditCP(lightNode); OSG::setName(lightNode, lightName); beginEditCP(rootNode); rootNode->addChild(lightNode); rootNode->addChild(beaconNode); endEditCP(rootNode); setLightSettings(light, handler); vrScenegraph::update(true); } } } } } catch (std::exception const& e) { cout << "type: " << typeid(e).name() << endl; cout << "message: " << e.what() << endl << endl; } }
static Q3CString relative_path(const QDir & destdir, Q3CString relto) { QDir fromdir(relto); Q3CString from = Q3CString(fromdir.absPath().toAscii().constData()); Q3CString to = Q3CString(destdir.absPath().toAscii().constData()); const char * cfrom = from; const char * cto = to; int lastsep = -1; int index = 0; for (;;) { char f = cfrom[index]; char t = cto[index]; if (f == 0) { switch (t) { case 0: // same path return ""; case '/': // to = .../aze/qsd/wxc, from = .../aze => qsd/wxc/ return (cto + index + 1) + Q3CString("/"); default: // to = .../aze/qsd/wxc, from = .../az => ../aze/qsd/wxc/ return "../" + Q3CString(cto + lastsep + 1) + "/"; } } else if (t == f) { if (t == '/') lastsep = index; index += 1; } else if (t == 0) { Q3CString r; const char * p = cfrom+index; do { if (*p == '/') r += "../"; } while (*++p != 0); if (f == '/') // to = .../aze, from = .../aze/qsd/wxc => ../../ return r; else // to = .../az, from = .../aze/qsd/wxc => ../../../az/ return ("../" + r + (cto + lastsep + 1)) + "/"; } else { // to = .../aze, from = .../iop/klm => ../../aze/ Q3CString r = "../"; const char * p = cfrom + lastsep + 1; while (*p != 0) if (*p++ == '/') r += "../"; return (r + (cto + lastsep + 1)) + "/"; } } }
void PackageDialog::extractPackage() { QString s = QFileDialog::getOpenFileName( lastDir.isEmpty() ? QString(".") : lastDir, tr("Qucs Packages")+" (*.qucs);;"+ tr("Any File")+" (*)", this, 0, tr("Enter a Package File Name")); if(s.isEmpty()) { reject(); return; } QFileInfo Info(s); lastDir = Info.dirPath(true); // remember last directory QFile PkgFile(s); if(!PkgFile.open(QIODevice::ReadOnly)) { if(Info.extension().isEmpty()) s += ".qucs"; PkgFile.setName(s); if(!PkgFile.open(QIODevice::ReadOnly)) { MsgText->append(tr("ERROR: Cannot open package!")); ButtClose->setDisabled(false); return; } } QDataStream Stream(&PkgFile); QDir currDir = QucsSettings.QucsHomeDir; QString Version; Q_UINT16 Checksum; Q_UINT32 Code, Length; // First read and check header. QByteArray Content = PkgFile.readAll(); if(strncmp(Content.data(), "Qucs package ", 13) != 0) { MsgText->append(tr("ERROR: File contains wrong header!")); goto ErrorEnd; } Version = QString(Content.data()+13); if(!checkVersion(Version)) { MsgText->append(tr("ERROR: Wrong version number!")); goto ErrorEnd; } // checksum correct ? PkgFile.at(HEADER_LENGTH-2); Stream >> Checksum; *((Q_UINT16*)(Content.data()+HEADER_LENGTH-2)) = 0; if(Checksum != qChecksum(Content.data(), Content.size())) { MsgText->append(tr("ERROR: Checksum mismatch!")); goto ErrorEnd; } Content.resize(0); // dispose memory // work on all files and directories in the package for(;;) { if(PkgFile.atEnd()) break; Stream >> Code >> Length; switch(Code) { case CODE_DIR: if(extractDirectory(PkgFile, Length, currDir) > 0) break; goto ErrorEnd; case CODE_DIR_END: MsgText->append(tr("Leave directory \"%1\"").arg(currDir.absPath())); currDir.cdUp(); break; case CODE_FILE: if(extractFile(PkgFile, Length, currDir) > 0) break; goto ErrorEnd; case CODE_LIBRARY: if(extractLibrary(PkgFile, Length) > 0) break; goto ErrorEnd; default: MsgText->append(tr("ERROR: Package is corrupt!")); goto ErrorEnd; } } MsgText->append(" "); MsgText->append(tr("Successfully extracted package!")); ErrorEnd: MsgText->append(" "); ButtClose->setDisabled(false); PkgFile.close(); }
ScriptAction::ScriptAction(const QString& scriptconfigfile, const QDomElement& element) : KAction() , Kross::Api::ScriptContainer() , d( new ScriptActionPrivate() ) // initialize d-pointer class { QString name = element.attribute("name"); QString text = element.attribute("text"); QString description = element.attribute("description"); QString file = element.attribute("file"); QString icon = element.attribute("icon"); QString version = element.attribute("version"); bool ok; int v = version.toInt(&ok); if(ok) d->version = v; if(file.isEmpty()) { if(text.isEmpty()) text = name; } else { if(name.isEmpty()) name = file; if(text.isEmpty()) text = file; } //d->scriptcontainer = Manager::scriptManager()->getScriptContainer(name); QString interpreter = element.attribute("interpreter"); if(interpreter.isNull()) setEnabled(false); else setInterpreterName( interpreter ); if(file.isNull()) { setCode( element.text().stripWhiteSpace() ); if(description.isNull()) description = text; ScriptContainer::setName(name); } else { QDir dir = QFileInfo(scriptconfigfile).dir(true); d->packagepath = dir.absPath(); QFileInfo fi(dir, file); file = fi.absFilePath(); setEnabled(fi.exists()); setFile(file); if(icon.isNull()) icon = KMimeType::iconForURL( KURL(file) ); if(description.isEmpty()) description = QString("%1<br>%2").arg(text.isEmpty() ? name : text).arg(file); else description += QString("<br>%1").arg(file); ScriptContainer::setName(file); } KAction::setName(name.latin1()); KAction::setText(text); setDescription(description); KAction::setIcon(icon); // connect signal connect(this, SIGNAL(activated()), this, SLOT(activate())); }