void AddAction::updateObjects() { QStringList names; theObjects->clear(); uniqueProgramMap.clear(); nameProgramMap.clear(); DCOPClient *theClient = KApplication::kApplication()->dcopClient(); QCStringList theApps = theClient->registeredApplications(); for(QCStringList::iterator i = theApps.begin(); i != theApps.end(); ++i) { if(!QString(*i).find("anonymous")) continue; if(!QString(*i).find(i18n( "anonymous" ))) continue; QRegExp r("(.*)-[0-9]+"); QString name = r.exactMatch(QString(*i)) ? r.cap(1) : *i; if(names.contains(name)) continue; names += name; KListViewItem *a = new KListViewItem(theObjects, name); uniqueProgramMap[a] = name == QString(*i); nameProgramMap[a] = *i; QCStringList theObjects = theClient->remoteObjects(*i); for(QCStringList::iterator j = theObjects.begin(); j != theObjects.end(); ++j) if(*j != "ksycoca" && *j != "qt")// && getFunctions(*i, *j).count()) new KListViewItem(a, *j); } updateFunctions(); }
Arts::Buffer *MCOPDCOPObject::callFunction(MCOPEntryInfo *entry, TQCString ifaceName, const TQByteArray &data) { Arts::Object workingObject = Arts::SubClass(string(ifaceName)); Arts::DynamicRequest request(workingObject); request.method(string(entry->functionName())); if(entry->signatureList().size() > 0) { QCStringList list = entry->signatureList(); QCStringList::iterator it; for(it = list.begin(); it != list.end(); ++it) { TQCString param = *it; kdDebug() << "PARAM: " << param << endl; TQDataStream argStream(data, IO_ReadOnly); if(param == "long") request.param(MCOPDCOPTools::getLong(argStream)); else if(param == "string") request.param(MCOPDCOPTools::getString(argStream)); } } Arts::AnyRef result; if(!request.invoke(result)) return 0; Arts::Buffer *newBuffer = new Arts::Buffer(); result.write(newBuffer); return newBuffer; }
void EditAction::updateDCOPObjects() { theDCOPObjects->clear(); DCOPClient *theClient = TDEApplication::kApplication()->dcopClient(); if(theDCOPApplications->currentText().isNull() || theDCOPApplications->currentText().isEmpty()) return; QCStringList theObjects = theClient->remoteObjects(nameProgramMap[theDCOPApplications->currentText()].utf8()); if(!theObjects.size() && theDCOPApplications->currentText() == (*theAction).program()) theDCOPObjects->insertItem((*theAction).object()); for(QCStringList::iterator j = theObjects.begin(); j != theObjects.end(); ++j) if(*j != "tdesycoca" && *j != "qt" && AddAction::getFunctions(nameProgramMap[theDCOPApplications->currentText()], *j).count()) theDCOPObjects->insertItem(TQString::fromUtf8(*j)); updateDCOPFunctions(); }
const QStringList AddAction::getFunctions(const QString app, const QString obj) { QStringList ret; DCOPClient *theClient = KApplication::kApplication()->dcopClient(); QCStringList theApps = theClient->remoteFunctions(app.utf8(), obj.utf8()); for(QCStringList::iterator i = theApps.begin(); i != theApps.end(); ++i) if( *i != "QCStringList interfaces()" && *i != "QCStringList functions()" && *i != "QCStringList objects()" && *i != "QCStringList find(QCString)" ) ret += QString::fromUtf8(*i); return ret; }
TQCString StubProcess::commaSeparatedList(QCStringList lst) { if (lst.count() == 0) return TQCString(""); QCStringList::Iterator it = lst.begin(); TQCString str = *it; for (it++; it!=lst.end(); it++) { str += ','; str += *it; } return str; }
bool KIMProxy::initialize() { if ( !m_initialized ) { m_initialized = true; // we should only do this once, as registeredToDCOP() will catch any new starts // So there is no error from a failed query when using tdelibs 3.2, which don't have this servicetype if ( KServiceType::serviceType( IM_SERVICE_TYPE ) ) { //kdDebug( 790 ) << k_funcinfo << endl; TQCString dcopObjectId = "KIMIface"; // see what apps implementing our service type are out there KService::List offers = KServiceType::offers( IM_SERVICE_TYPE ); KService::List::iterator offer; typedef TQValueList<TQCString> QCStringList; QCStringList registeredApps = d->dc->registeredApplications(); QCStringList::iterator app; const QCStringList::iterator end = registeredApps.end(); // for each registered app for ( app = registeredApps.begin(); app != end; ++app ) { //kdDebug( 790 ) << " considering: " << *app << endl; //for each offer for ( offer = offers.begin(); offer != offers.end(); ++offer ) { TQCString dcopService = (*offer)->property("X-DCOP-ServiceName").toString().latin1(); if ( !dcopService.isEmpty() ) { //kdDebug( 790 ) << " is it: " << dcopService << "?" << endl; // get the application name ( minus any process ID ) TQCString instanceName = (*app).left( dcopService.length() ); // if the application implements the dcop service, add it if ( instanceName == dcopService ) { m_apps_available = true; //kdDebug( 790 ) << " app name: " << (*offer)->name() << ", has instance " << *app << ", dcopService: " << dcopService << endl; if ( !m_im_client_stubs.find( dcopService ) ) { kdDebug( 790 ) << "App " << *app << ", dcopObjectId " << dcopObjectId << " found, using it for presence info." << endl; m_im_client_stubs.insert( *app, new KIMIface_stub( d->dc, *app, dcopObjectId ) ); pollApp( *app ); } } } } } } } return !m_im_client_stubs.isEmpty(); }
bool KonqSidebarTree::tabSupport() { // see if the newTab() dcop function is available (i.e. the sidebar is embedded into konqueror) DCOPRef ref(kapp->dcopClient()->appId(), topLevelWidget()->name()); DCOPReply reply = ref.call("functions()"); if (reply.isValid()) { QCStringList funcs; reply.get(funcs, "QCStringList"); for (QCStringList::ConstIterator it = funcs.begin(); it != funcs.end(); ++it) { if ((*it) == "void newTab(QString url)") { return true; break; } } } return false; }
bool NoatunSensor::isRunning() { TQRegExp rx("(noatun)|(noatun-\\d+)"); QCStringList list = client->registeredApplications(); TQValueList<TQCString>::iterator it; it = list.begin(); bool foundNoatun = false; noatunID = "noatun"; while( foundNoatun == false && it != list.end() ) { if( rx.search( *it ) != -1 ) { foundNoatun = true; noatunID = *it; } ++it; } return ( client->isApplicationRegistered ( noatunID ) ); }
int KDEsuClient::exec(const QCString &prog, const QCString &user, const QCString &options, const QCStringList &env) { QCString cmd; cmd = "EXEC "; cmd += escape(prog); cmd += " "; cmd += escape(user); if (!options.isEmpty() || !env.isEmpty()) { cmd += " "; cmd += escape(options); for(QCStringList::ConstIterator it = env.begin(); it != env.end(); ++it) { cmd += " "; cmd += escape(*it); } } cmd += "\n"; return command(cmd); }
static void continueInWindow(QString _wname) { QCString wname = _wname.latin1(); int id = -1; QCStringList apps = kapp->dcopClient()->registeredApplications(); for (QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it) { QCString &clientId = *it; if (qstrncmp(clientId, wname, wname.length()) != 0) continue; DCOPRef client(clientId.data(), wname + "-mainwindow#1"); DCOPReply result = client.call("getWinID()"); if (result.isValid()) { id = (int)result; break; } } KWin::activateWindow(id); }
void EditAction::updateDCOPApplications() { TQStringList names; theDCOPApplications->clear(); DCOPClient *theClient = TDEApplication::kApplication()->dcopClient(); QCStringList theApps = theClient->registeredApplications(); for(QCStringList::iterator i = theApps.begin(); i != theApps.end(); ++i) { if(!TQString(*i).find("anonymous")) continue; TQRegExp r("(.*)-[0-9]+"); TQString name = r.exactMatch(TQString(*i)) ? r.cap(1) : *i; if(names.contains(name)) continue; names += name; theDCOPApplications->insertItem(name); uniqueProgramMap[name] = name == TQString(*i); nameProgramMap[name] = *i; } updateDCOPObjects(); }
int main(int argc, char** argv) { KAboutData about ("kdvi", I18N_NOOP("KDVI"), "1.4", description, KAboutData::License_GPL, "Markku Hinhala, Stephan Kebekus", I18N_NOOP("This program displays Device Independent (DVI) files which are produced by the TeX typesetting system.\n" "This KDVI version is based on original code from KDVI version 0.43 and xdvik.")); about.addAuthor ("Stefan Kebekus", I18N_NOOP("Current Maintainer."), "*****@*****.**", "http://www.mi.uni-koeln.de/~kebekus"); about.addAuthor ("Markku Hinhala", I18N_NOOP("Author of kdvi 0.4.3")); about.addAuthor ("Nicolai Langfeldt", I18N_NOOP("Maintainer of xdvik")); about.addAuthor ("Paul Vojta", I18N_NOOP("Author of xdvi")); about.addCredit ("Philipp Lehmann", I18N_NOOP("Testing and bug reporting.")); about.addCredit ("Wilfried Huss", I18N_NOOP("Re-organisation of source code.")); KCmdLineArgs::init(argc, argv, &about); KCmdLineArgs::addCmdLineOptions(options); KApplication app; // see if we are starting with session management if (app.isRestored()) { RESTORE(KViewShell); } else { KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); if (args->isSet("unique")) { // With --unique, we need 2 arguments. if (args->count() < 1) { args->usage(); exit(-1); } // Find the fully qualified file name of the file we are // loading. Complain, if we are given a URL which does not point // to a local file. KURL url(args->url(0)); if (!url.isValid()) { kdError(4300) << QString(I18N_NOOP("The URL %1 is not well-formed.")).arg(args->arg(0)) << endl; return -1; } if (!url.isLocalFile()) { kdError(4300) << QString(I18N_NOOP("The URL %1 does not point to a local file. You can only specify local " "files if you are using the '--unique' option.")).arg(args->arg(0)) << endl; return -1; } QString qualPath = QFileInfo(url.path()).absFilePath(); app.dcopClient()->attach(); // We need to register as "kviewshell" to stay compatible with existing DCOP-skripts. QCString id = app.dcopClient()->registerAs("unique-kviewshell"); if (id.isNull()) kdError(4300) << "There was an error using dcopClient()->registerAs()." << endl; QCStringList apps = app.dcopClient()->registeredApplications(); for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it ) { if ((*it).find("kviewshell") == 0) { QByteArray data, replyData; QCString replyType; QDataStream arg(data, IO_WriteOnly); bool result; arg << qualPath.stripWhiteSpace(); if (!app.dcopClient()->call( *it, "kmultipage", "is_file_loaded(QString)", data, replyType, replyData)) kdError(4300) << "There was an error using DCOP." << endl; else { QDataStream reply(replyData, IO_ReadOnly); if (replyType == "bool") { reply >> result; if (result == true) { if (app.dcopClient()->send( *it, "kmultipage", "jumpToReference(QString)", url.ref()) == true) { app.dcopClient()->detach(); return 0; } } } else kdError(4300) << "The DCOP function 'doIt' returned an unexpected type of reply!"; } } }
int main(int argc, char **argv) { KAboutData about("kstcmd", I18N_NOOP("Kst Command Line"), "1.0", I18N_NOOP("Kst Command Line"), KAboutData::License_GPL, I18N_NOOP("(c) 2005-2006 The University of Toronto"), 0, "http://kst.kde.org/"); about.addAuthor("Staikos Computing Services Inc.", I18N_NOOP("Developed for the University of Toronto"), "*****@*****.**"); KCmdLineArgs::init(argc, argv, &about); KCmdLineArgs::addCmdLineOptions(options); KApplication a(false, false); QCString session; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->count() > 0) { session = args->arg(0); } setvbuf(stdout, 0, _IONBF, 0); if (session.isEmpty()) { DCOPClient *client = KApplication::dcopClient(); QCStringList apps = client->registeredApplications(); QCStringList ksts; for (QCStringList::ConstIterator i = apps.begin(); i != apps.end(); ++i) { if ((*i).left(4) == "kst-") { ksts += *i; } } if (ksts.isEmpty()) { char *l = readline(_T("Kst does not appear to be running. Start a new session? ")); if (!l) { return ERR_NONE; } QString lstr = l; free(l); l = 0L; if (lstr.stripWhiteSpace().lower()[0] != 'y') { return ERR_NONE; } int pid = 0; QString err; int rc = KApplication::startServiceByDesktopName("kst", QString::null, &err, &session, &pid); if (rc != 0) { printf(_T("Error starting session: %s\n"), err.latin1()); return ERR_STARTING_SESSION; } if (session.isEmpty()) { session = QString("kst-%1").arg(pid).latin1(); } time_t startTime = time(NULL); printf("%s", _T("Waiting for Kst to start.")); while (!client->isApplicationRegistered(session)) { if (time(NULL) - startTime > 30) { printf("%s", _T("\nTimeout waiting for Kst to start\n")); return ERR_STARTING_SESSION; } printf("."); sleep(1); } printf("\n"); } else if (ksts.count() > 1) { QCString parentKst = QCString("kst-") + QString::number(getppid()).latin1(); if (ksts.contains(parentKst)) { session = parentKst; } else { printf("%s", _T("Please choose a session number to attach to:\n")); int j = 0; for (QCStringList::ConstIterator i = ksts.begin(); i != ksts.end(); ++i) { printf(_T("%2d: %s\n"), ++j, (*i).data()); } printf("> "); char choice[10]; QString l = fgets(choice, 4, stdin); l = l.stripWhiteSpace(); if (l.isEmpty()) { printf("%s", _T("No session found.\n")); return ERR_NO_SESSION; } bool ok = false; int nchoice = l.toInt(&ok); if (ok && nchoice > 0 && nchoice <= j) { session = ksts[nchoice - 1]; } else { printf("%s", _T("No session found.\n")); return ERR_NO_SESSION; } } } else { session = ksts[0]; } } DCOPRef ref(session.data(), "KstScript"); if (ref.isNull() || !KApplication::dcopClient()->registeredApplications().contains(ref.app())) { printf(_T("Error attaching to session %s\n"), session.data()); return ERR_ATTACHING; } printf(_T("Attached to Kst session %s\n"), session.data()); return run(ref); }
int StubProcess::ConverseStub(int check) { TQCString line, tmp; while (1) { line = readLine(); if (line.isNull()) return -1; if (line == "tdesu_stub") { // This makes parsing a lot easier. enableLocalEcho(false); if (check) writeLine("stop"); else writeLine("ok"); } else if (line == "display") { writeLine(display()); } else if (line == "display_auth") { #ifdef Q_WS_X11 writeLine(displayAuth()); #else writeLine(""); #endif } else if (line == "dcopserver") { if (m_bDCOPForwarding) writeLine(dcopServer()); else writeLine("no"); } else if (line == "dcop_auth") { if (m_bDCOPForwarding) writeLine(dcopAuth()); else writeLine("no"); } else if (line == "ice_auth") { if (m_bDCOPForwarding) writeLine(iceAuth()); else writeLine("no"); } else if (line == "command") { writeLine(m_Command); } else if (line == "path") { TQCString path = getenv("PATH"); if (!path.isEmpty() && path[0] == ':') path = path.mid(1); if (m_User == "root") if (!path.isEmpty()) path = "/usr/local/sbin:/usr/sbin:/sbin:" + path; else if (strcmp(__TDE_BINDIR, "/usr/bin") == 0) { path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin"; } else { path = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:" __TDE_BINDIR ":/usr/bin:/bin"; } writeLine(path); } else if (line == "user") { writeLine(m_User); } else if (line == "priority") { tmp.setNum(m_Priority); writeLine(tmp); } else if (line == "scheduler") { if (m_Scheduler == SchedRealtime) writeLine("realtime"); else writeLine("normal"); } else if (line == "xwindows_only") { if (m_bXOnly) writeLine("no"); else writeLine("yes"); } else if (line == "app_startup_id") { QCStringList env = environment(); TQCString tmp; for( QCStringList::ConstIterator it = env.begin(); it != env.end(); ++it ) { if( (*it).find( "DESKTOP_STARTUP_ID=" ) == 0 ) tmp = (*it).mid( strlen( "DESKTOP_STARTUP_ID=" )); } if( tmp.isEmpty()) tmp = "0"; writeLine(tmp); } else if (line == "app_start_pid") { // obsolete tmp.setNum(getpid()); writeLine(tmp); } else if (line == "environment") { // additional env vars QCStringList env = environment(); for( QCStringList::ConstIterator it = env.begin(); it != env.end(); ++it ) writeLine( *it ); writeLine( "" ); } else if (line == "end") { return 0; } else { kdWarning(900) << k_lineinfo << "Unknown request: -->" << line << "<--\n"; return 1; } } return 0; }
int main(int argc, char *argv[]) { int i_file, i_v, i_curve; int i_plot; QString fullPath; KAboutData aboutData("kst", I18N_NOOP("Kst"), KSTVERSION, description, KAboutData::License_GPL, I18N_NOOP("(c) 2000-2007 Barth Netterfield"), 0, "http://kst.kde.org/"); aboutData.addAuthor("Barth Netterfield", I18N_NOOP("Original author and maintainer."), "*****@*****.**", "http://omega.astro.utoronto.ca/"); aboutData.addAuthor("Staikos Computing Services Inc.", I18N_NOOP("Developed for the University of Toronto."), "*****@*****.**", "http://www.staikos.net/"); aboutData.addAuthor("Sumus Technology Limited", I18N_NOOP("Developed for the University of British Columbia"), "*****@*****.**", "http://www.sumusltd.com/"); aboutData.addAuthor("Rick Chern", I18N_NOOP("University of British Columbia"), "", ""); aboutData.addAuthor("Duncan Hanson", I18N_NOOP("University of British Columbia"), "", ""); aboutData.addAuthor("Nicolas Brisset", "", "", ""); aboutData.addAuthor("Matthew Truch", "", "http://matt.truch.net/", "*****@*****.**"); aboutData.addAuthor("Theodore Kisner", "", "*****@*****.**", ""); aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails")); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KImageIO::registerFormats(); KstDialogs::replaceSelf(new KstGuiDialogs); KstData::replaceSelf(new KstGuiData); KstApp::initialize(); atexit(exitHelper); if (app.isRestored()) { RESTORE(KstApp) } else { KstApp *kst = new KstApp; InType in; QColor color; QCStringList ycolList; QCStringList matrixList; QCStringList yEqList; QCStringList psdList; QCStringList hsList; QCStringList errorList; unsigned int i_ycol; QCStringList::Iterator hs_string; QCStringList::Iterator eq_i; QCStringList::Iterator mat_i; bool showQuickStart = false; bool showDataWizard = false; bool nOK; int n_y = 0; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); CheckForCMDErrors(args); QString wizardfile = args->getOption("w"); QString printfile = args->getOption("print"); QString pngfile = args->getOption("png"); bool print_and_exit = false; if (printfile != "<none>") { print_and_exit = true; } if (pngfile != "<none>") { print_and_exit = true; } if (!print_and_exit) { app.setMainWidget(kst); QRect rect = KGlobalSettings::desktopGeometry(kst); kst->resize(5 * rect.width() / 6, 5 * rect.height() / 6); kst->show(); } // get Y axis columns ycolList = args->getOptionList("y"); matrixList = args->getOptionList("z"); yEqList = args->getOptionList("ye"); psdList = args->getOptionList("p"); hsList = args->getOptionList("h"); errorList = args->getOptionList("e"); // y axis or PSD specified, so the files are data files, not kst files. n_y = ycolList.count() + psdList.count() + hsList.count() + yEqList.count() + matrixList.count(); if (n_y > 0) { QString creatingEquations = i18n("Creating equations"); QString creatingCurves = i18n("Creating curves"); QString creatingPlots = i18n("Creating plots"); int count; int handled; kst->slotUpdateProgress( 0, 0, QString::null ); SetCMDOptions(args, in, n_y); KstTopLevelViewPtr tlv = kst->activeView(); if (!tlv) { // if there was no active view then we create one... kst->newWindow(false); tlv = kst->activeView(); } if (!tlv) { kstdError() << i18n("Can't create a view.") << endl; return 0; } CreatePlots(in, tlv); Kst2DPlotList plist = kstObjectSubList<KstViewObject, Kst2DPlot>(tlv->children()); i_plot = 0; Kst2DPlotPtr plot = *plist.at(i_plot); KstVCurveList vcurves = kstObjectSubList<KstBaseCurve,KstVCurve>(plot->Curves); // make stand alone equations if there are no files if (args->count() < 1) { if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); if (xeq) { count = yEqList.size(); handled = 0; kst->slotUpdateProgress( count, handled, creatingEquations ); for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { eqS = *eq_i; if (NoVectorEq(eqS)) { KstEquationPtr eq = new KstEquation(KST::suggestEQName(eqS), eqS, min, max, n); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, KstColorSequence::next(vcurves,plot->backgroundColor())); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eq.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } } handled++; kst->slotUpdateProgress( count, handled, creatingEquations ); } } } } // make the requested curves for each data file count = args->count(); handled = 0; kst->slotUpdateProgress( count, handled, creatingCurves ); for (i_curve = i_v = 0, i_file = 0; i_file < args->count(); i_file++) { // make the file if (QFile::exists(args->arg(i_file))) { fullPath = QFileInfo(args->arg(i_file)).absFilePath(); } else { fullPath = args->arg(i_file); } KstDataSourcePtr file = KstDataSource::loadSource(fullPath); if (file) { if (!file->isValid() || file->isEmpty()) { kstdError() << i18n("No data in file %1. Trying to continue...").arg(args->arg(i_file)) << endl; // The file might get data later! } KST::dataObjectList.lock().writeLock(); KST::dataSourceList.append(file); KST::dataObjectList.lock().unlock(); KstRVectorPtr yvector; KstRVectorPtr evector; KstVCurvePtr curve; KstPSDPtr psd; KstHistogramPtr hs; KstRVectorPtr xvector; if (!ycolList.isEmpty()) { // if there are some xy plots // make the x axis vector xvector = GetOrCreateVector(args->getOption("x"), file, in); if (xvector) { // make the y axis vectors for (i_ycol = 0; i_ycol < ycolList.count(); ++i_ycol ) { yvector = GetOrCreateVector(*(ycolList.at(i_ycol)), file, in); if (yvector) { // make the curves color = KstColorSequence::next(vcurves,plot->backgroundColor()); curve = new KstVCurve(KST::suggestCurveName(yvector->tag(), false), KstVectorPtr(xvector), KstVectorPtr(yvector), 0L, 0L, 0L, 0L, color); if (in.has_points) { curve->setHasPoints(true); curve->setHasLines(false); } if (i_ycol<errorList.count()) { evector = GetOrCreateVector(*(errorList.at(i_ycol)), file, in); if (evector) { curve->setYError(KstVectorPtr(evector)); curve->setYMinusError(KstVectorPtr(evector)); } } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(curve.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(curve.data()); if (in.sep_plots) { plot->setTagName(curve->tag()); i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } // end (if they are separate plots) } } // next y col } } // end (if there are some xy plots) if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq, eq_ok; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { KstEquationPtr eq; eqS = *eq_i; ProcessEq(eqS, file, in, &eq_ok); if (xeq) { eq = new KstEquation(KST::suggestEQName(eqS), eqS, min,max,n); } else { if (!xvector) { xvector = GetOrCreateVector(args->getOption("x"), file, in); } if (xvector) { eq = new KstEquation(KST::suggestEQName(eqS), eqS, KstVectorPtr(xvector), true); } } if (eq) { KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(eq->tag(), true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, KstColorSequence::next(vcurves,plot->backgroundColor())); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eq.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { plot->setTagName(eq->tag()); i_plot++; if (i_plot <in.n_plots) { plot = *plist.at(i_plot); } } } } } if (psdList.count() > 0) { // if there are some psd plots KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (QCStringList::ConstIterator it = psdList.begin(); it != psdList.end(); ++it) { yvector = GetOrCreateVector(*it, file, in); if (yvector) { color = KstColorSequence::next(vcurves,plot->backgroundColor()); psd = new KstPSD( KST::suggestPSDName(yvector->tag()), // FIXME: this was yvector->field(), is this right? KstVectorPtr(yvector), in.rate, true, in.len, true, true, in.VUnits, in.RUnits, WindowOriginal); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(psd->tag(), true), psd->vX(), psd->vY(), 0L, 0L, 0L, 0L, color); if (in.has_points) { vc->setHasPoints(true); vc->setHasLines(false); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(psd.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { plot->setTagName(psd->tag()); i_plot++; if (i_plot <in.n_plots) { plot = *plist.at(i_plot); } } } } // next psd } // end (if there are some psds) if (hsList.count() > 0) { // if there are some histograms double max, min; int N; KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (hs_string = hsList.begin(); hs_string != hsList.end(); ++hs_string) { yvector = GetOrCreateVector(*hs_string, file, in); if (yvector) { color = KstColorSequence::next(vcurves,plot->backgroundColor()); KstHistogram::AutoBin(KstVectorPtr(yvector), &N, &max, &min); hs = new KstHistogram(KST::suggestHistogramName(yvector->tag()), KstVectorPtr(yvector), min, max, N, KST_HS_NUMBER); KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(hs->tag(), true), hs->vX(), hs->vY(), 0L, 0L, 0L, 0L, color); vc->setHasPoints(false); vc->setHasLines(false); vc->setHasBars(true); vc->setBarStyle(1); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(hs.data()); KST::dataObjectList.append(vc.data()); KST::dataObjectList.lock().unlock(); plot->addCurve(vc.data()); if (in.sep_plots) { plot->setTagName(hs->tag()); i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } } } // next histogram } // end (if there are some histograms) if (matrixList.count() > 0) { // if there are some matrixes for (mat_i = matrixList.begin(); mat_i != matrixList.end(); ++mat_i) { QString tag_name = KST::suggestMatrixName(*mat_i); if (!file->isValidMatrix(*mat_i)) { startupErrors.append(i18n("Failed to create matrix '%1' from file '%2'.").arg(*mat_i).arg(file->fileName())); } KstRMatrixPtr matrix = new KstRMatrix(file, *mat_i, KstObjectTag(tag_name, file->tag()), 0,0,-1,-1,false,false,0); // xStart, yStart, xNumSteps, yNumSteps, //doAve, doSkip, skip); // Time to create the image from the matrix tag_name = KST::suggestImageName(matrix->tag()); QStringList palList = KPalette::getPaletteList(); QString pal; if (palList.contains("IDL 13 RAINBOW")) { pal = QString("IDL 13 RAINBOW"); } else { pal = QString(*palList.at(0)); } KPalette* newPal = new KPalette(pal); KstImagePtr image = new KstImage(tag_name, KstMatrixPtr(matrix), 0.0, 1.0, true, newPal); plot->addCurve(KstBaseCurvePtr(image)); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(image.data()); KST::dataObjectList.lock().unlock(); image = 0L; // drop the reference if (in.sep_plots) { plot->setTagName(matrix->tag()); i_plot++; if (i_plot < in.n_plots) { plot = *plist.at(i_plot); } } } } } else { startupErrors.append(i18n("Failed to load file '%1'.").arg(args->arg(i_file))); } handled++; kst->slotUpdateProgress( count, handled, creatingCurves ); } // next data file count = in.n_plots; handled = 0; kst->slotUpdateProgress( count, handled, creatingPlots ); for (i_plot = 0; i_plot < in.n_plots; i_plot++) { plot = *plist.at(i_plot); plot->generateDefaultLabels(); // if we have only images in a plot then set the scale mode to AUTO (instead of AUTOBORDER) KstImageList images = kstObjectSubList<KstBaseCurve,KstImage>(plot->Curves); if (images.count() == plot->Curves.count()) { plot->setXScaleMode(AUTO); plot->setYScaleMode(AUTO); } if (plot->Curves.count() > 3 || in.dolegend) { KstViewLegendPtr vl = plot->getOrCreateLegend(); vl->resizeFromAspect(0.1, 0.1, 0.2, 0.1); vl->setBorderWidth(2); } handled++; kst->slotUpdateProgress( count, handled, creatingPlots ); } kst->slotUpdateProgress( 0, 0, QString::null ); } else if (args->count() > 0) { // open a kst file // some of the options can be overridden kst->openDocumentFile(args->arg(0), args->getOption("F"), // override FileName args->getOption("n").toInt(&nOK), // override number of frames args->getOption("f").toInt(&nOK), // override starting frame args->getOption("s").toInt(&nOK), // override skip args->isSet("a"), // add averaging !print_and_exit); // delayed } else { //kst->openDocumentFile(); showQuickStart = true; } if (args->isSet("nq")) { showQuickStart = false; } if (args->isSet("w")) { showDataWizard = true; showQuickStart = false; } if (printfile != "<none>") { kst->forceUpdate(); kst->immediatePrintToFile(printfile, false); } if (pngfile != "<none>") { kst->forceUpdate(); kst->immediatePrintToPng(pngfile); } kst->document()->setModified(false); if (print_and_exit) { delete kst; return 0; } else { kst->updateDialogs(); if (showQuickStart) { kst->showQuickStartDialog(); } if (showDataWizard) { kst->showDataWizardWithFile(wizardfile); } for (size_t i = 0; i < startupErrors.size(); ++i) { KstDebug::self()->log(startupErrors[i], KstDebug::Error); } startupErrors.clear(); } // LEAVE THIS HERE - causes crashes otherwise! int rc = app.exec(); delete kst; return rc; } return app.exec(); }
int main( int argc, char **argv ) { TDEAboutData about( "tdefile", I18N_NOOP( "tdefile" ), TDEFILEVERSION, I18N_NOOP("A commandline tool to read and modify metadata of files." ), TDEAboutData::License_LGPL, "(c) 2002, Carsten Pfeiffer", 0 /*text*/, "http://devel-home.kde.org/~pfeiffer/", "*****@*****.**" ); about.addAuthor( "Carsten Pfeiffer", 0, "*****@*****.**", "http://devel-home.kde.org/~pfeiffer/" ); TDECmdLineArgs::init( argc, argv, &about ); TDECmdLineArgs::addCmdLineOptions( options ); TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); bool useGUI = args->isSet( "dialog" ); TDEApplication app( useGUI, useGUI ); TQPtrList<FileProps> m_props; m_props.setAutoDelete( true ); bool quiet = args->isSet( "quiet" ); if ( args->isSet( "supportedMimetypes" ) ) printSupportedMimeTypes(); int files = args->count(); if ( files == 0 ) TDECmdLineArgs::usage( i18n("No files specified") ); // exit()s if ( args->isSet( "dialog" ) ) { showPropertiesDialog( args ); return true; } TQStringList groupsToUse; QCStringList suppliedGroups = args->getOptionList( "groups" ); QCStringList::ConstIterator it = suppliedGroups.begin(); for ( ; it != suppliedGroups.end(); ++it ) groupsToUse.append( TQString::fromLocal8Bit( (*it) ) ); TQString mimeType; for ( int i = 0; i < files; i++ ) { if ( args->isSet( "mimetype" ) ) printMimeTypes( args ); FileProps *props = new FileProps( args->url(i).path(), groupsToUse ); if ( props->isValid() ) m_props.append( props ); else { if ( !quiet ) { cerr << args->arg(i) << ": " << i18n("Cannot determine metadata").local8Bit().data() << endl; } delete props; } } processMetaDataOptions( m_props, args ); m_props.clear(); // force destruction/sync of props cout.flush(); return 0; }
int main(int argc, char *argv[]) { int i_file, i_v, i_curve; int i_plot; KAboutData aboutData( "kst", I18N_NOOP("Kst"), "0.95-devel", description, KAboutData::License_GPL, I18N_NOOP("(c) 2000-2003 Barth Netterfield"), 0, "http://extragear.kde.org/apps/kst.php"); aboutData.addAuthor("Barth Netterfield", I18N_NOOP("Original author and maintainer."), "*****@*****.**", "http://omega.astro.utoronto.ca/"); aboutData.addAuthor("Staikos Computing Services Inc.", I18N_NOOP("Developed for the University of Toronto."), "*****@*****.**", "http://www.staikos.net/"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KImageIO::registerFormats(); if (app.isRestored()) { RESTORE(KstApp) } else { KstApp *kst = new KstApp; struct InType in; QColor color; QCStringList ycolList; QCStringList yEqList; QCStringList psdList; QCStringList hsList; QCStringList errorList; unsigned int i_ycol; QCStringList::Iterator psd; QCStringList::Iterator hs; QCStringList::Iterator eq_i; bool nOK; /* temp variables: these all get stuck into list objects */ KstDataSourcePtr file; KstRVector *xvector=NULL; KstRVector *yvector; KstRVector *evector; KstVCurve *curve; KstPSDCurve *psdcurve; KstEquationCurve *eqcurve; KstHistogram *hscurve; KstPlot *plot; int n_y, n_eq=0; /* Parse command line args */ KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); CheckForCMDErrors(args); // Initialise the plugin loader and collection. PluginCollection::self(); /* get Y axis collums */ ycolList = args->getOptionList("y"); yEqList = args->getOptionList("ye"); psdList = args->getOptionList("p"); hsList = args->getOptionList("h"); errorList = args->getOptionList("e"); // y axis or PSD specified, so the files are data files, not kst files. n_y = ycolList.count() + psdList.count() + hsList.count() + yEqList.count(); if (n_y > 0) { SetCMDOptions(args, in, n_y); CreatePlots(in); i_plot = 0; plot = KST::plotList.at(i_plot); /* make stand alone equations if there are no files */ if (args->count()<1) { if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); if (xeq) { for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { eqS = *eq_i; if (NoVectorEq(eqS)) { eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+ "-" + eqS, eqS, min,max,n, KstColorSequence::next()); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eqcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(eqcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } } } } } /* Make the requested curves for each data file */ for (i_curve = i_v = 0, i_file = 0; i_file < args->count(); i_file++) { /* Make the file */ file = KstDataSource::loadSource(args->arg(i_file)); if (!file) { kdWarning() << I18N_NOOP("Error: No data in file: ") << args->arg(i_file) << endl; delete kst; exit(0); } if (!file->isValid() || file->frameCount() < 1) { kdWarning() << I18N_NOOP("Error: No data in file: ") << args->arg(i_file) << endl; // The file might get data later! } KST::dataObjectList.lock().writeLock(); KST::dataSourceList.append(file); KST::dataObjectList.lock().writeUnlock(); if (!ycolList.isEmpty()) { // if there are some xy plots /* make the x axis vector */ xvector = GetOrCreateVector(args->getOption("x"), file, in); /* make the y axis vectors */ for (i_ycol = 0; i_ycol < ycolList.count(); ++i_ycol ) { yvector = GetOrCreateVector(*(ycolList.at(i_ycol)), file, in); /* make the curves */ color = KstColorSequence::next(); curve = new KstVCurve(QString("C") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(xvector), KstVectorPtr(yvector), 0L, 0L, color); if (in.has_points) { curve->setHasPoints(true); curve->setHasLines(false); } if (i_ycol<errorList.count()) { evector = GetOrCreateVector(*(errorList.at(i_ycol)), file, in); curve->setYError(KstVectorPtr(evector)); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(curve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(curve); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) plot = KST::plotList.at(i_plot); } // end (if they are separate plots) } // next y col } // end (if there are some xy plots) if (!yEqList.isEmpty()) { QString eqS; double max, min; int n; bool xeq, eq_ok; SetEqXRanges(args->getOption("xe"), &min, &max, &n, &xeq); for (eq_i = yEqList.begin(); eq_i != yEqList.end(); ++eq_i) { eqS = *eq_i; ProcessEq(eqS, file, in, &eq_ok); if (xeq) { eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+ "-" + eqS, eqS, min,max,n, KstColorSequence::next()); } else { if (xvector==NULL) xvector = GetOrCreateVector(args->getOption("x"), file, in); eqcurve = new KstEquationCurve(QString("E")+QString::number(n_eq+1)+eqS, eqS, KstVectorPtr(xvector), true, KstColorSequence::next()); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(eqcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(eqcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } } if (psdList.count() > 0) { // if there are some psd plots KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for(psd = psdList.begin(); psd != psdList.end(); ++psd ) { yvector = GetOrCreateVector(*psd, file, in); color = KstColorSequence::next(); psdcurve = new KstPSDCurve(QString("P") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(yvector), in.rate, in.len, in.VUnits,in.RUnits, color); if (in.has_points) { psdcurve->setHasPoints(true); psdcurve->setHasLines(false); } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(psdcurve); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(psdcurve); if (in.sep_plots) { i_plot++; if (i_plot <in.n_plots) plot = KST::plotList.at(i_plot); } } // next psd } // end (if there are some psds) if (hsList.count()>0) { // if there are some histograms double max, min; int N; KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList); for (hs = hsList.begin(); hs != hsList.end(); ++hs ) { yvector = GetOrCreateVector(*hs, file, in); color = KstColorSequence::next(); KstHistogram::AutoBin(KstVectorPtr(yvector), &N, &max, &min); hscurve = new KstHistogram(QString("H") + QString::number(1+i_curve++) + "-" + yvector->getField(), KstVectorPtr(yvector), min, max, N, KST_HS_NUMBER, color); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(KstDataObjectPtr(hscurve)); KST::dataObjectList.lock().writeUnlock(); plot->addCurve(hscurve); if (in.sep_plots) { i_plot++; if (i_plot < in.n_plots) plot = KST::plotList.at(i_plot); } } // next histogram } // end (if there are some histograms) } // next data file for (i_plot = 0; i_plot < in.n_plots; i_plot++) { KST::plotList.at(i_plot)->GenerateDefaultLabels(); } KST::plotList.setPlotCols(in.n_cols); } else if (args->count() > 0) { /* open a kst file */ /* some of the options can be overridden */ kst->openDocumentFile(args->arg(0), args->getOption("F"), // override FileName // override number of frames args->getOption("n").toInt(&nOK), // override starting frame args->getOption("f").toInt(&nOK), // override skip args->getOption("s").toInt(&nOK), // add averaging args->isSet("a")); } else { //kst->openDocumentFile(); } QString printfile; printfile = args->getOption("print"); QString pngfile; pngfile = args->getOption("png"); bool print_and_exit = false; if (printfile!="<none>") { args->clear(); kst->forceUpdate(); kst->immediatePrintToFile(printfile); print_and_exit = true; } if (pngfile!="<none>") { args->clear(); kst->forceUpdate(); kst->immediatePrintToPng(pngfile); print_and_exit = true; } if (print_and_exit) { delete kst; exit(0); } else { args->clear(); app.setMainWidget(kst); kst->show(); } // LEAVE THIS HERE - causes crashes otherwise! int rc = app.exec(); delete kst; return rc; } return app.exec(); }
void PrintWrapper::slotPrint() { KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; #endif /* HAVE_SIGACTION && !HAVE_SIGSET*/ // read variables from command line QString printer = args->getOption("d"); QString title = args->getOption("t"); int ncopies = QString(args->getOption("n")).toInt(); QString job_mode = args->getOption("j"); QString system = args->getOption("system"); QCStringList optlist = args->getOptionList("o"); QMap<QString,QString> opts; KURL::List files; QStringList filestoprint; force_stdin = args->isSet("stdin"); docopy = args->isSet( "c" ); bool nodialog = !(args->isSet("dialog")); if( isatty( 0 )) { kdDebug( 500 ) << "stdin is a terminal, disabling it" << endl; check_stdin = false; } // parse options for (QCStringList::ConstIterator it=optlist.begin(); it!=optlist.end(); ++it) { QStringList l = QStringList::split('=',QString(*it),false); if (l.count() >= 1) opts[l[0]] = (l.count() == 2 ? l[1] : QString::null); } // read file list for (int i=0; i<args->count(); i++) files.append(args->url(i)); // some clean-up args->clear(); // set default values if necessary if (job_mode == "console") job_output = 1; else if (job_mode == "none") job_output = 2; else job_output = 0; // some checking if ( files.count() > 0) { check_stdin = false; if( force_stdin ) { showmsg(i18n("A file has been specified on the command line. Printing from STDIN will be disabled."), 1); force_stdin = false; } } if (nodialog && files.count() == 0 &&!force_stdin && !check_stdin ) { errormsg(i18n("When using '--nodialog', you must at least specify one file to print or use the '--stdin' flag.")); } if( check_stdin ) { // check if there's any input on stdin fd_set in; struct timeval tm; tm.tv_sec = 0; tm.tv_usec = 0; FD_ZERO( &in ); FD_SET( 0, &in ); if( select( 1, &in, NULL, NULL, &tm ) ) { // we have data on stdin if ( read( 0, &readchar, 1 ) > 0 ) { force_stdin = true; check_stdin = false; dataread = true; kdDebug( 500 ) << "input detected on stdin" << endl; } else { force_stdin = check_stdin = false; kdDebug( 500 ) << "stdin closed and empty" << endl; } } else kdDebug( 500 ) << "no input on stdin at startup" << endl; } // force_stdin ? or also check_stdin ? KPrinter::ApplicationType dialog_mode = (force_stdin || nodialog ? KPrinter::StandAlone : KPrinter::StandAlonePersistent); KPrinter::setApplicationType(dialog_mode); if (!force_stdin) KPrinter::addStandardPage(KPrinter::FilesPage); KPrinter kprinter; if (nodialog) { KMPrinter *prt(0); KMManager *mgr = KMManager::self(); mgr->printerList(false); if (!printer.isEmpty()) prt = mgr->findPrinter(printer); else prt = mgr->defaultPrinter(); if (prt == 0) errormsg(i18n("The specified printer or the default printer could not be found.")); else if (!prt->autoConfigure(&kprinter)) errormsg(i18n("Operation aborted.")); } else if (!printer.isEmpty()) kprinter.setSearchName(printer); kprinter.setDocName(title); kprinter.initOptions(opts); kprinter.setOption("kde-filelist", files.toStringList().join("@@")); kdDebug( 500 ) << kprinter.option( "kde-filelist" ) << endl; if (ncopies > 0) kprinter.setNumCopies(ncopies); if (nodialog) slotPrintRequested(&kprinter); else { dlg = KPrintDialog::printerDialog(&kprinter, 0); if (dlg) { connect(dlg, SIGNAL(printRequested(KPrinter*)), SLOT(slotPrintRequested(KPrinter*))); if( check_stdin ) { notif = new QSocketNotifier( 0, QSocketNotifier::Read, this ); connect( notif, SIGNAL( activated( int )), this, SLOT( slotGotStdin())); kdDebug( 500 ) << "waiting for input on stdin" << endl; } dlg->exec(); delete dlg; } else errormsg(i18n("Unable to construct the print dialog.")); }