Beispiel #1
0
void IQmolApplication::open(QString const& file)
{
   // This is the first thing that is called once the event loop has started,
   // even if there is no actual file to open (empty file name).  This is an
   // ideal time to check if OpenBabel is around.  
   initOpenBabel();

   MainWindow* mw;
   QWidget* window(QApplication::activeWindow());
   if ( !(mw = qobject_cast<MainWindow*>(window)) ) {
      mw = new MainWindow();
      connect(mw, SIGNAL(quit()), this, SLOT(quitRequest()));
      QApplication::setActiveWindow(mw);
   }

   QFileInfo info(file);
   if (info.exists()) mw->open(file);
   hideSplash();
   mw->show();
   mw->raise();

   // Now we can load jobs from the preferences, if we try to do it 
   // before now, the dialog appears under the splash screen
   Process::JobMonitor::instance().loadJobListFromPreferences();

   static bool connected(false);
   if (!connected) {
      connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quitRequest()));
      connected = true;
   }
   QLOG_INFO() << "Number of threads:" << QThread::idealThreadCount();
   QLOG_INFO() << "Active    threads:" << QThreadPool::globalInstance()->activeThreadCount();
}
Beispiel #2
0
void Project::slotOpenProject(const KURL &url)
{
  kdDebug(24000) << "Open recent project: " << url <<endl;
  if ( !url.isEmpty() )
  {
    if ( !QExtFileInfo::exists(url, true, d->m_mainWindow) )
    {
      emit hideSplash();
      if (KMessageBox::questionYesNo(d->m_mainWindow,
           i18n("<qt>The file <b>%1</b> does not exist.<br> Do you want to remove it from the list?</qt>").arg(url.prettyURL(0, KURL::StripFileProtocol)), QString::null, KStdGuiItem::del(), i18n("Keep") )
           == KMessageBox::Yes)
      {
        d->m_projectRecent->removeURL(url);
      } else
        d->m_projectRecent->setCurrentItem(0);
    } else
    {
      d->loadProject ( url );
      emit eventHappened("after_project_open", url.url(), QString::null);
    }
  }
}
Beispiel #3
0
int
main(int argc, char **argv)
{
    svSystemSpecificInitialisation();

#ifdef Q_WS_X11
#if QT_VERSION >= 0x040500
//    QApplication::setGraphicsSystem("raster");
#endif
#endif

#ifdef Q_OS_MAC
    if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) {
        // Fix for OS/X 10.9 font problem
        QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
    }
#endif

    SVApplication application(argc, argv);

    QStringList args = application.arguments();

    signal(SIGINT,  signalHandler);
    signal(SIGTERM, signalHandler);

#ifndef Q_OS_WIN32
    signal(SIGHUP,  signalHandler);
    signal(SIGQUIT, signalHandler);
#endif

    bool audioOutput = true;
    bool oscSupport = true;

    if (args.contains("--help") || args.contains("-h") || args.contains("-?")) {
        cerr << QApplication::tr(
            "\nSonic Visualiser is a program for viewing and exploring audio data\nfor semantic music analysis and annotation.\n\nUsage:\n\n  %1 [--no-audio] [--no-osc] [<file> ...]\n\n  --no-audio: Do not attempt to open an audio output device\n  --no-osc: Do not provide an Open Sound Control port for remote control\n  <file>: One or more Sonic Visualiser (.sv) and audio files may be provided.\n").arg(argv[0]) << endl;
        exit(2);
    }

    if (args.contains("--no-audio")) audioOutput = false;
    if (args.contains("--no-osc")) oscSupport = false;

    QApplication::setOrganizationName("sonic-visualiser");
    QApplication::setOrganizationDomain("sonicvisualiser.org");
    QApplication::setApplicationName(QApplication::tr("Sonic Visualiser"));

    QSplashScreen *splash = 0;

    QSettings settings;

    settings.beginGroup("Preferences");
    if (settings.value("show-splash", true).toBool()) {
        QPixmap pixmap(":/icons/sv-splash.png");
        QPainter painter;
        painter.begin(&pixmap);
        QString text = QString("v%1").arg(SV_VERSION);
        painter.drawText
            (pixmap.width() - painter.fontMetrics().width(text) - 10,
             10 + painter.fontMetrics().ascent(),
             text);
        painter.end();
        splash = new QSplashScreen(pixmap);
        splash->show();
        QTimer::singleShot(5000, splash, SLOT(hide()));
        application.processEvents();
    }
    settings.endGroup();

    settings.beginGroup("RDF");
    if (!settings.contains("rdf-indices")) {
        QStringList list;
        list << "http://www.vamp-plugins.org/rdf/plugins/index.txt";
        settings.setValue("rdf-indices", list);
    }
    settings.endGroup();

    QIcon icon;
    int sizes[] = { 16, 22, 24, 32, 48, 64, 128 };
    for (int i = 0; i < int(sizeof(sizes)/sizeof(sizes[0])); ++i) {
        icon.addFile(QString(":icons/sv-%1x%2.png").arg(sizes[i]).arg(sizes[i]));
    }
    QApplication::setWindowIcon(icon);

    QString language = QLocale::system().name();

    settings.beginGroup("Preferences");
    language = settings.value("locale", language).toString();
    settings.endGroup();

    QTranslator qtTranslator;
    QString qtTrName = QString("qt_%1").arg(language);
    SVDEBUG << "Loading " << qtTrName << "... ";
    bool success = false;
    if (!(success = qtTranslator.load(qtTrName))) {
        QString qtDir = getenv("QTDIR");
        if (qtDir != "") {
            success = qtTranslator.load
                (qtTrName, QDir(qtDir).filePath("translations"));
        }
    }
    if (!success) {
        SVDEBUG << "Failed\nFailed to load Qt translation for locale" << endl;
    } else {
        cerr << "Done" << endl;
    }
    application.installTranslator(&qtTranslator);

    QTranslator svTranslator;
    QString svTrName = QString("sonic-visualiser_%1").arg(language);
    SVDEBUG << "Loading " << svTrName << "... ";
    svTranslator.load(svTrName, ":i18n");
    SVDEBUG << "Done" << endl;
    application.installTranslator(&svTranslator);

    StoreStartupLocale();

    // Permit size_t and PropertyName to be used as args in queued signal calls
    qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName");

    MainWindow *gui = new MainWindow(audioOutput, oscSupport);
    application.setMainWindow(gui);
    InteractiveFileFinder::setParentWidget(gui);
    TransformUserConfigurator::setParentWidget(gui);
    if (splash) {
        QObject::connect(gui, SIGNAL(hideSplash()), splash, SLOT(hide()));
    }

    QDesktopWidget *desktop = QApplication::desktop();
    QRect available = desktop->availableGeometry();

    int width = (available.width() * 2) / 3;
    int height = available.height() / 2;
    if (height < 450) height = (available.height() * 2) / 3;
    if (width > height * 2) width = height * 2;

    settings.beginGroup("MainWindow");

    QSize size = settings.value("size", QSize(width, height)).toSize();
    gui->resizeConstrained(size);

    if (settings.contains("position")) {
        QRect prevrect(settings.value("position").toPoint(), size);
        if (!(available & prevrect).isEmpty()) {
            gui->move(prevrect.topLeft());
        }
    }

    if (settings.value("maximised", false).toBool()) {
        gui->setWindowState(Qt::WindowMaximized);
    }

    settings.endGroup();
    
    gui->show();

    // The MainWindow class seems to have trouble dealing with this if
    // it tries to adapt to this preference before the constructor is
    // complete.  As a lazy hack, apply it explicitly from here
    gui->preferenceChanged("Property Box Layout");

    application.m_readyForFiles = true; // Ready to receive files from e.g. Apple Events

    for (QStringList::iterator i = args.begin(); i != args.end(); ++i) {

        if (i == args.begin()) continue;
        if (i->startsWith('-')) continue;

        QString path = *i;

        application.handleFilepathArgument(path, splash);
    }
    
    for (QStringList::iterator i = application.m_filepathQueue.begin(); i != application.m_filepathQueue.end(); ++i) {
        QString path = *i;
        application.handleFilepathArgument(path, splash);
    }
    
#ifdef HAVE_FFTW3F
    settings.beginGroup("FFTWisdom");
    QString wisdom = settings.value("wisdom").toString();
    if (wisdom != "") {
        fftwf_import_wisdom_from_string(wisdom.toLocal8Bit().data());
    }
#ifdef HAVE_FFTW3
    wisdom = settings.value("wisdom_d").toString();
    if (wisdom != "") {
        fftw_import_wisdom_from_string(wisdom.toLocal8Bit().data());
    }
#endif
    settings.endGroup();
#endif

    if (splash) splash->finish(gui);
    delete splash;

/*
    TipDialog tipDialog;
    if (tipDialog.isOK()) {
        tipDialog.exec();
    }
*/
    int rv = application.exec();

    gui->hide();

    cleanupMutex.lock();

    if (!cleanedUp) {
        TransformFactory::deleteInstance();
        TempDirectory::getInstance()->cleanup();
        cleanedUp = true;
    }

    application.releaseMainWindow();

#ifdef HAVE_FFTW3F
    settings.beginGroup("FFTWisdom");
    char *cwisdom = fftwf_export_wisdom_to_string();
    if (cwisdom) {
        settings.setValue("wisdom", cwisdom);
        free(cwisdom);
    }
#ifdef HAVE_FFTW3
    cwisdom = fftw_export_wisdom_to_string();
    if (cwisdom) {
        settings.setValue("wisdom_d", cwisdom);
        free(cwisdom);
    }
#endif
    settings.endGroup();
#endif

    FileSource::debugReport();
    
    delete gui;

    cleanupMutex.unlock();

    return rv;
}
void DebuggerManager::slotNewProjectLoaded(const QString &projectname, const KURL &, const KURL &)
{
  if(m_client)
  {
    
    disconnect(m_client, SIGNAL(updateStatus(DebuggerUI::DebuggerStatus)), m_debuggerui, SLOT(slotStatus(DebuggerUI::DebuggerStatus)));

    delete m_client;
    m_client = NULL;
  }
  enableAction("*", false);
  
  // Remove all breakpoints
  m_breakpointList->clear();
  
  if(m_debuggerui)
  {
    delete m_debuggerui;
    m_debuggerui = NULL;
  }
  //kdDebug(24002) << "DebuggerManager::slotNewProjectLoaded " << projectname << ", " << Project::ref()->debuggerClient << endl;

  // Load new client
  if(!projectname.isEmpty())
  {

    KTrader::OfferList offers = KTrader::self()->query("Quanta/Debugger");
    KTrader::OfferList::ConstIterator iterDbg;
    for(iterDbg = offers.begin(); iterDbg != offers.end(); ++iterDbg)
    {
      KService::Ptr service = *iterDbg;
      if(Project::ref()->debuggerClient() == service->name())
      {
        int errCode = 0;
//Workaround for dynamic_cast not working correctly on SUSE 10, gcc 4.0.2
//The correct way should be a simple:
// m_client = KParts::ComponentFactory::createInstanceFromService<DebuggerClient>(service, this, 0, QStringList(), &errCode);
        QObject* obj = KParts::ComponentFactory::createInstanceFromService<QObject>(service, this, 0, QStringList(), &errCode);
        if (obj && obj->inherits("DebuggerClient"))
          m_client = static_cast<DebuggerClient *>(obj);

        //kdDebug(24002) << service->name() << " (" << m_client << ")" << endl;

        if(!m_client)
        {
          emit hideSplash();
          KMessageBox::error(NULL, i18n("<qt>Unable to load the debugger plugin, error code %1 was returned: <b>%2</b>.</qt>").arg(errCode).arg(KLibLoader::self()->lastErrorMessage()), i18n("Debugger Error"));
        }
        break;
      }
    }
  }

  // Tell client to load its settings
  if (m_client)
  {
    QDomNode nodeThisDbg;
    QDomDocument *dom = Project::ref()->sessionDom();
    QDomNode projectNode = dom->firstChild().firstChild();
    QDomNode nodeDbg  = projectNode.namedItem("debuggers");
    if(nodeDbg.isNull())
    {
      nodeDbg = dom->createElement("debuggers");
      projectNode.appendChild(nodeDbg);
    }

    // Load this project's mapped paths
    m_pathmapper->readConfig();
    
    // Load this projects debugger's settings
    nodeThisDbg = nodeDbg.namedItem(m_client->getName());
    if(nodeThisDbg.isNull())
    {
      nodeThisDbg = dom->createElement(m_client->getName());
      nodeDbg.appendChild(nodeThisDbg);
    }

    m_client->readConfig(nodeThisDbg);

    // recreate UI
    m_debuggerui = new DebuggerUI(this, "debuggerui");
    connect(m_client, SIGNAL(updateStatus(DebuggerUI::DebuggerStatus)), m_debuggerui, SLOT(slotStatus(DebuggerUI::DebuggerStatus)));
    
    // Load saved breakpoints
    if(Project::ref()->debuggerPersistentBreakpoints())
    {
      QDomNode nodeBreakpoints = nodeDbg.namedItem("breakpoints");
      if(!nodeBreakpoints.isNull())
      {
        QDomNode child = nodeBreakpoints.firstChild();
        while(!child.isNull())
        {
          DebuggerBreakpoint* bp = new DebuggerBreakpoint();
          bp->setFilePath( child.attributes().namedItem("filepath").nodeValue());
          bp->setClass( child.attributes().namedItem("class").nodeValue());
          bp->setFunction( child.attributes().namedItem("function").nodeValue());
          bp->setCondition( child.attributes().namedItem("condition").nodeValue());
          bp->setLine( child.attributes().namedItem("line").nodeValue().toLong());
          if(child.attributes().namedItem("type").nodeValue() == "true")
            bp->setType(DebuggerBreakpoint::ConditionalTrue);
          else if(child.attributes().namedItem("type").nodeValue() == "change")
            bp->setType(DebuggerBreakpoint::ConditionalChange);
          else
            bp->setType(DebuggerBreakpoint::LineBreakpoint);
          
          // Update client and ui
          m_client->addBreakpoint(bp);
          m_breakpointList->add(bp);
          
          // loop
          child = child.nextSibling();
        }
      }
    }

    // Load saved Watches
    if(Project::ref()->debuggerPersistentWatches())
    {
      QDomNode nodeWatches = nodeDbg.namedItem("watches");
      if(!nodeWatches.isNull())
      {
        QDomNode child = nodeWatches.firstChild();
        while(!child.isNull())
        {
          QString watch = child.attributes().namedItem("name").nodeValue();
          DebuggerVariable *var = new DebuggerVariable(watch, "", DebuggerVariableTypes::Undefined);
          m_debuggerui->addVariable(var);
          m_client->addWatch(watch);

          child = child.nextSibling();
        }
      }
    }

  }

  initClientActions();

  // Disable all debugactions that need a session (ie not breakpoints, etc)
  slotDebugStartSession();
}