void DictApplet::sendCommand(const QCString &fun, const QString &data)
{
  if (waiting > 0) {
    waiting = 1;
    delayedFunc = fun.copy();
    delayedData = data;
    return;
  }

  DCOPClient *client = kapp->dcopClient();
  if (!client->isApplicationRegistered("kdict")) {
    KApplication::startServiceByDesktopName("kdict");
    waiting = 1;
    delayedFunc = fun.copy();
    delayedData = data;
    QTimer::singleShot(100, this, SLOT(sendDelayedCommand()));
    return;
  } else {
    QCStringList list = client->remoteObjects("kdict");
    if (list.findIndex("KDictIface")==-1) {
      waiting = 1;
      delayedFunc = fun.copy();
      delayedData = data;
      QTimer::singleShot(100, this, SLOT(sendDelayedCommand()));
      return;
    }
  }

  client->send("kdict","default",fun,data);
}
Exemple #2
0
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;
}
Exemple #3
0
QCStringList MCOPDCOPObject::functionsDynamic()
{
	QCStringList returnList;
	
	TQMap<TQCString, MCOPEntryInfo *>::iterator it;
	for(it = d->dynamicFunctions.begin(); it != d->dynamicFunctions.end(); ++it)
		returnList.append(it.key());
	
	return returnList;
}
Exemple #4
0
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();
}
Exemple #5
0
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;
}
Exemple #6
0
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;
}
Exemple #7
0
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();
}
Exemple #8
0
  Capabilities Capabilities::fromResponse( const Response & ehlo ) {
    Capabilities c;

    // first, check whether the response was valid and indicates success:
    if ( !ehlo.isOk()
         || ehlo.code() / 10 != 25 // ### restrict to 250 only?
         || ehlo.lines().empty() )
      return c;

    QCStringList l = ehlo.lines();

    for ( QCStringList::const_iterator it = ++l.constBegin() ; it != l.constEnd() ; ++it )
      c.add( QString::fromLatin1(*it) );

    return c;
  }
Exemple #9
0
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;
}
Exemple #10
0
int main(int argc, char *argv[])
{
  xsltStylesheetPtr cur = NULL;
  xmlDocPtr doc, res;

  const char *params[16 + 1];
  int nbparams = 0;
  params[nbparams] = NULL;

  KAboutData aboutData( "umbodoc", 0, ki18n("Umbrello UML Modeller autonomous code generator"),
                        umbrelloVersion(), ki18n(description), KAboutData::License_GPL,
                        ki18n("(c) 2006 Gael de Chalendar (aka Kleag), (c) 2002-2006 Umbrello UML Modeller Authors"), KLocalizedString(),
                        "http://uml.sf.net/");
  aboutData.addAuthor(ki18n("Gael de Chalendar (aka Kleag)"),KLocalizedString(), "*****@*****.**");
  aboutData.addAuthor(ki18n("Umbrello UML Modeller Authors"), KLocalizedString(), "*****@*****.**");
  KCmdLineArgs::init( argc, argv, &aboutData );

  KCmdLineOptions options;
  options.add("+[File]", ki18n("File to transform"));
  options.add("xslt <url>", ki18n("The XSLT file to use"));
  KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.

  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

  QCStringList xsltOpt = args->getOptionList("xslt");
  if (xsltOpt.size() > 0)
  {
    QString xsltFile(xsltOpt.last());

    xmlSubstituteEntitiesDefault(1);
    xmlLoadExtDtdDefaultValue = 1;
    cur = xsltParseStylesheetFile((const xmlChar *)xsltFile.latin1());
    doc = xmlParseFile(args->url( 0 ).url().latin1());
    res = xsltApplyStylesheet(cur, doc, params);
    xsltSaveResultToFile(stdout, res, cur);

    xsltFreeStylesheet(cur);
    xmlFreeDoc(res);
    xmlFreeDoc(doc);

    xsltCleanupGlobals();
    xmlCleanupParser();
  }
  return(0);
}
Exemple #11
0
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 ) );
}
Exemple #12
0
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);
}
Exemple #13
0
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();
}
Exemple #14
0
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);
}
Exemple #15
0
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();
}
void DictApplet::sendDelayedCommand()
{
  if (waiting > 100) {   // timeout after ten seconds
    waiting = 0;
    return;
  }

  DCOPClient *client = kapp->dcopClient();
  if (!client->isApplicationRegistered("kdict")) {
    waiting++;
    QTimer::singleShot(100, this, SLOT(sendDelayedCommand()));
    return;
  } else {
    QCStringList list = client->remoteObjects("kdict");
    if (list.findIndex("KDictIface")==-1) {
      waiting++;
      QTimer::singleShot(100, this, SLOT(sendDelayedCommand()));
      return;
    }
  }

  client->send("kdict","default",delayedFunc,delayedData);
  waiting = 0;
}
Exemple #17
0
void Qhp::initialize()
{
  /*
  <QtHelpProject version="1.0">
    <namespace>mycompany.com.myapplication.1_0</namespace>
    <virtualFolder>doc</virtualFolder>
    <customFilter name="My Application 1.0">
      <filterAttribute>myapp</filterAttribute>
      <filterAttribute>1.0</filterAttribute>
    </customFilter>
    <filterSection>
      <filterAttribute>myapp</filterAttribute>
      <filterAttribute>1.0</filterAttribute>
  ..
  */
  QCString nameSpace       = Config_getString(QHP_NAMESPACE);
  QCString virtualFolder   = Config_getString(QHP_VIRTUAL_FOLDER);

  m_doc.declaration("1.0", "UTF-8");

  const char * rootAttributes[] =
  { "version", "1.0", 0 };

  m_doc.open("QtHelpProject", rootAttributes);
  m_doc.openCloseContent("namespace", nameSpace);
  m_doc.openCloseContent("virtualFolder", virtualFolder);

  // Add custom filter
  QCString filterName = Config_getString(QHP_CUST_FILTER_NAME);
  if (!filterName.isEmpty())
  {
    const char * tagAttributes[] = 
    { "name", filterName, 0 };
    m_doc.open("customFilter", tagAttributes);

    QCStringList customFilterAttributes = QCStringList::split(' ', Config_getString(QHP_CUST_FILTER_ATTRS));
    for (int i = 0; i < (int)customFilterAttributes.count(); i++)
    {
      m_doc.openCloseContent("filterAttribute", customFilterAttributes[i]);
    }
    m_doc.close("customFilter");
  }

  m_doc.open("filterSection");

  // Add section attributes
  QCStringList sectionFilterAttributes = QCStringList::split(' ',
      Config_getString(QHP_SECT_FILTER_ATTRS));
  if (!sectionFilterAttributes.contains("doxygen"))
  {
    sectionFilterAttributes << "doxygen";
  }
  for (int i = 0; i < (int)sectionFilterAttributes.count(); i++)
  {
    m_doc.openCloseContent("filterAttribute", sectionFilterAttributes[i]);
  }

  m_toc.open("toc");

  // Add extra root node
  QCString fullProjectname = getFullProjectName();
  QCString indexFile = "index"+Doxygen::htmlFileExtension;
  const char * const attributes[] =
  { "title", fullProjectname,
    "ref",   indexFile,
    NULL
  };
  m_toc.open("section", attributes);
  m_prevSectionTitle = getFullProjectName();
  m_prevSectionLevel = 1;
  m_sectionLevel = 1;

  m_index.open("keywords");
  m_files.open("files");
}
Exemple #18
0
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!";
          }
        }
      }
Exemple #19
0
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);
}
Exemple #20
0
extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
{
  // here we go, construct the Kate version
  QString kateVersion = KateApp::kateVersion();

  KAboutData aboutData ("kate", I18N_NOOP("Kate"), kateVersion.latin1(),
                        I18N_NOOP( "Kate - Advanced Text Editor" ), KAboutData::License_LGPL_V2,
                        I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0, "http://kate.kde.org");

  aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "*****@*****.**", "http://www.babylon2k.de");
  aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "*****@*****.**", "http://www.alweb.dk");
  aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "*****@*****.**","http://stud3.tuwien.ac.at/~e9925371");
  aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "*****@*****.**");
  aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "*****@*****.**" );
  aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "*****@*****.**");
  aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "*****@*****.**");
  aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "*****@*****.**");
  aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "*****@*****.**");
  aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "*****@*****.**" );
  aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "*****@*****.**");
  aboutData.addAuthor ("Christian Gebauer", 0, "*****@*****.**" );
  aboutData.addAuthor ("Simon Hausmann", 0, "*****@*****.**" );
  aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "*****@*****.**");
  aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "*****@*****.**");
  aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "*****@*****.**");
  aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "*****@*****.**");

  aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "*****@*****.**");
  aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "*****@*****.**");
  aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
  aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
  aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
  aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
  aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
  aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
  aboutData.addCredit ("Daniel Naber","","");
  aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
  aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
  aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
  aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");

  aboutData.setTranslator(I18N_NOOP2("NAME OF TRANSLATORS","Your names"), I18N_NOOP2("EMAIL OF TRANSLATORS","Your emails"));

  // command line args init and co
  KCmdLineArgs::init (argc, argv, &aboutData);
  KCmdLineArgs::addCmdLineOptions (options);
  KCmdLineArgs::addTempFileOption();
  KateApp::addCmdLineOptions ();

  // get our command line args ;)
  KCmdLineArgs* args = KCmdLineArgs::parsedArgs();

  // now, first try to contact running kate instance if needed
  if ( args->isSet("use") || (::getenv("KATE_PID")!=0) )
  {
    DCOPClient client;
    client.attach ();

    // get all attached clients ;)
    QCStringList allClients = client.registeredApplications();

    // search for a kate app client, use the first found
    QCString kateApp;

    if ( args->isSet("start") )
    {
      for (unsigned int i=0; i < allClients.count(); i++)
      {
        if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
        {
          DCOPRef ref( allClients[i], "KateApplication" );
          QString s = ref.call( "session" );
          if ( QString(args->getOption("start")) == s )
          {
            kateApp = allClients[i];
            break;
          }
        }
      }
    }
    else if ( (args->isSet("pid")) || (::getenv("KATE_PID") !=0 ) )
    {
      QCString tryApp;
      if ( args->isSet("pid") )
        tryApp = args->getOption("pid");
      else
        tryApp = ::getenv("KATE_PID");

      if ( client.isApplicationRegistered( tryApp.prepend("kate-") ) )
        kateApp = tryApp;
    }
    else
    {
      for (unsigned int i=0; i < allClients.count(); ++i)
      {
        if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
        {
          kateApp = allClients[i];
          break;
        }
      }
    }

    // found a matching kate client ;)
    if (!kateApp.isEmpty())
    {
      kdDebug () << "kate app: " << kateApp << endl;
      // make kdeinit happy
      client.registerAs( "kate" );

      DCOPRef kRef (kateApp, "KateApplication");

      if (args->isSet ("start"))
        kRef.call( "activateSession", QString (args->getOption("start")) );

      QString enc = args->isSet("encoding") ? args->getOption("encoding") : QCString("");

      bool tempfileSet = KCmdLineArgs::isTempFileSet();

      for (int z=0; z<args->count(); z++)
        kRef.call( "openURL", args->url(z), enc, tempfileSet );

      if( args->isSet( "stdin" ) )
      {
        QTextIStream input(stdin);

        // set chosen codec
        QTextCodec *codec = args->isSet("encoding") ? QTextCodec::codecForName(args->getOption("encoding")) : 0;

        if (codec)
          input.setCodec (codec);

        QString line;
        QString text;

        do
        {
          line = input.readLine();
          text.append( line + "\n" );
        } while( !line.isNull() );

        kRef.call( "openInput", text );
      }

      int line = 0;
      int column = 0;
      bool nav = false;

      if (args->isSet ("line"))
      {
        line = args->getOption ("line").toInt();
        nav = true;
      }

      if (args->isSet ("column"))
      {
        column = args->getOption ("column").toInt();
        nav = true;
      }

      if (nav)
         kRef.call( "setCursor", line, column );

      // since the user tried to open a document, let us assume [s]he
      // wants to see that document.
      // ### what to do about the infamous focus stealing prevention?
      uint mwn = kRef.call("activeMainWindowNumber");
      QCString smwn;
      DCOPRef wRef( kateApp, QCString( "__KateMainWindow#") + smwn.setNum(mwn) );
      if ( wRef.call("minimized") )
      {
        if ( wRef.call( "maximized" ) )
          wRef.call( "maximize" );
        else
          wRef.call("restore");
      }
      wRef.call( "raise" );

      // stop startup notification
      KStartupInfo::appStarted(  );

      return 0;
    }
  }

  // construct the real kate app object ;)
  KateApp app (args);

  // app execution should already end :)
  if (app.shouldExit())
  {
    return 0;
  }

  // execute ourself ;)
  return app.exec();
}
Exemple #21
0
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();
}
Exemple #23
0
QCStringList KTorrentViewItem::getTorrentInfo(kt::TorrentInterface* tc)
{
	QCStringList info;
	const TorrentStats & s = tc->getStats();
	info.append(s.torrent_name.local8Bit());
	info.append(tc->statusToString().local8Bit());
	info.append(BytesToString(s.bytes_downloaded).local8Bit());
	info.append(BytesToString(s.total_bytes_to_download).local8Bit());
	info.append(BytesToString(s.bytes_uploaded).local8Bit());
	if (s.bytes_left_to_download == 0)
		info.append(KBytesPerSecToString(0).local8Bit());
	else
		info.append(KBytesPerSecToString(s.download_rate / 1024.0).local8Bit());
	
	info.append(KBytesPerSecToString(s.upload_rate / 1024.0).local8Bit());
	if (s.bytes_left_to_download == 0)
	{
		info.append(QCString(""));
	}
	else if (s.running) 
	{
		Uint32 secs = tc->getETA();
		if(secs == -1)
			info.append(i18n("infinity").local8Bit());
		else
			info.append(DurationToString(secs).local8Bit());
	}
	else
	{
		info.append(i18n("infinity").local8Bit());
	}
	
	info.append(QString::number(s.num_peers).local8Bit());
	info.append(QString(KGlobal::locale()->formatNumber(Percentage(s),2) + " %").local8Bit());
	info.append(KGlobal::locale()->formatNumber(kt::ShareRatio(s),2).local8Bit());
	info.append(QString::number(s.seeders_connected_to).local8Bit());
	info.append(QString::number(s.leechers_connected_to).local8Bit());
	return info;
}
Exemple #24
0
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;
}
Exemple #25
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();
}
Exemple #26
0
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."));
	}