QIcon TemplateManager::templateIcon(const QString& target, const QString& _template) { QFileInfo templateInfo(_template); const QString& base = pathForTemplate(target, templateInfo.path() + "/" + templateInfo.baseName()); QFileInfo file(base + ".png"); if(!file.exists()) file.setFile(file.path() + "/" + defaultTemplateName() + ".png"); return QIcon(file.filePath()); }
/** * First send a a new template, then send the dataTemplates for all stored * tables. */ void* IpfixDbReader::readFromDB(void* ipfixDbReader_) { IpfixDbReader* ipfixDbReader = (IpfixDbReader*)ipfixDbReader_; ipfixDbReader->registerCurrentThread(); msg(MSG_DIALOG, "IpfixDbReader: Start sending tables"); for(vector<string>::iterator i = ipfixDbReader->tables.begin(); i != ipfixDbReader->tables.end() && !ipfixDbReader->exitFlag; i++) { boost::shared_ptr<IpfixRecord::TemplateInfo> templateInfo(new IpfixRecord::TemplateInfo); if(ipfixDbReader->dbReaderSendNewTemplate(templateInfo, *i) != 0) { msg(MSG_ERROR, "IpfixDbReader: Template error, skip table"); continue; } ipfixDbReader->dbReaderSendTable(templateInfo, *i); ipfixDbReader->dbReaderDestroyTemplate(templateInfo); } ipfixDbReader->unregisterCurrentThread(); msg(MSG_DIALOG,"IpfixDbReader: Sending from database is done"); return 0; }
Project * App::CreateNewProject(const BMessage &settings) { Project *proj = NULL; BString projectName, targetName, projectPath, templateName, pldName; int32 projectType, scmType; bool createFolder, populateProject = true; settings.FindString("name",&projectName); settings.FindString("target",&targetName); settings.FindInt32("type",&projectType); settings.FindString("path",&projectPath); settings.FindInt32("scmtype", &scmType); settings.FindBool("createfolder",&createFolder); settings.FindString("template", &templateName); settings.FindString("pldfile", &pldName); if (templateName.CountChars() > 0) { // Templates are now a directory with a TEMPLATEINFO file. All files in the // directory are copies, allowing for much greater flexibility than before. BString projectFileName(projectName); projectFileName << ".pld"; DPath templatePath(gAppPath.GetFolder()); templatePath << "Templates" << templateName; // Copy the contents of the chosen template folder to the project path DPath sourcePath(templatePath); DPath destPath(gProjectPath); if (createFolder) { destPath << projectName; create_directory(destPath.GetFullPath(), 0700); } BString wildcard("'"); wildcard << sourcePath.GetFullPath() << "'/*"; ShellHelper shell("cp -a "); shell << wildcard; shell.AddQuotedArg(destPath.GetFullPath()); shell.Run(); // The copy command copies *everything*, so we have to delete the // TEMPLATEINFO file. DPath templateInfo(destPath); templateInfo << "TEMPLATEINFO"; BEntry infoEntry(templateInfo.GetFullPath()); infoEntry.Remove(); infoEntry.Unset(); DPath finalPath; // Load project and set info or create one, if needed. // If the settings contain the name of a .pld project file, we'll search // for that first. Assuming that it exists, we'll rename that file to the // project name specified. If it doesn't exist or the .pld name is empty, // we'll create a new project with the appropriate name. // The pldname field comes from the TEMPLATEINFO file, which can designate // the main project file in a template. This allows a template to have // multiple project files, such as for the Tracker Add-on development framework // which has both a project file for generating the actual addon and another // one which is the testing framework. bool createProjFile = true; if (pldName.CountChars() > 0) { // If a .pld project file was specified in TEMPLATEINFO, check to see if // the file exists and rename it. If it doesn't exist, we'll create a new // file, and if a .pld file already exists with the intended name, we won't // do anything except tell the user what's happened. DPath oldPldNamePath(destPath); oldPldNamePath << pldName; BEntry oldPldNameEntry(oldPldNamePath.GetFullPath()); DPath newPldNamePath(destPath); newPldNamePath << projectFileName; BEntry newPldNameEntry(newPldNamePath.GetFullPath()); if (newPldNameEntry.Exists()) { // createProjFile is false here only if there is a .pld file with the // user's chosen project name. If that is the case, we keep both files and // let the user sort it out. BString errMsg = B_TRANSLATE( "Project file '%projectname%.pld' already exists. The " "original file for this template is '%pldname%'. You'll need " "to open the project folder and figure out which one you wish to keep."); errMsg.ReplaceFirst("%projectname%", projectName); errMsg.ReplaceFirst("%pldname%", pldName); ShowAlert(errMsg); populateProject = createProjFile = false; finalPath = newPldNamePath; } else if (oldPldNameEntry.Exists()) { oldPldNameEntry.Rename(projectFileName.String()); populateProject = createProjFile = false; finalPath = newPldNamePath; } } if (createProjFile) { proj = Project::CreateProject(projectName.String(), targetName.String(), projectType, projectPath.String(), createFolder); if (proj) finalPath = proj->GetPath(); } else { proj = new Project(); if (proj->Load(finalPath.GetFullPath()) != B_OK) { delete proj; return NULL; } } } else { // This case is for stuff like the Quick Import feature proj = Project::CreateProject(projectName.String(), targetName.String(), projectType, projectPath.String(), createFolder); } if (!proj) return NULL; scm_t detectedSCM = DetectSCM(projectPath); proj->SetSourceControl(detectedSCM == SCM_NONE ? (scm_t)scmType : detectedSCM); gCurrentProject = proj; gProjectList->Lock(); gProjectList->AddItem(proj); gProjectList->Unlock(); BRect r(0,0,200,300); /* r.OffsetTo(gProjectWindowPoint); gProjectWindowPoint.x += 25; gProjectWindowPoint.y += 25; if (gProjectWindowPoint.x < 0) gProjectWindowPoint.x = 0; if (gProjectWindowPoint.y < 0) gProjectWindowPoint.y - 0; */ ProjectWindow *projwin = new ProjectWindow(r,gCurrentProject); projwin->Show(); BEntry entry(gCurrentProject->GetPath().GetFullPath()); if (entry.InitCheck() == B_OK) { entry_ref newprojref; entry.GetRef(&newprojref); UpdateRecentItems(newprojref); } if (populateProject) { entry_ref addRef; int32 i = 0; while (settings.FindRef("libs",i++,&addRef) == B_OK) { if (BEntry(&addRef).Exists()) proj->AddLibrary(DPath(addRef).GetFullPath()); } i = 0; BMessage addMsg(M_IMPORT_REFS); while (settings.FindRef("refs",i++,&addRef) == B_OK) addMsg.AddRef("refs",&addRef); PostToProjectWindow(&addMsg,NULL); } return proj; }
bool KoApplication::start() { ResetStarting resetStarting; // reset m_starting to false when we're done Q_UNUSED(resetStarting); // Find the *.desktop file corresponding to the kapp instance name KoDocumentEntry entry = KoDocumentEntry(KoDocument::readNativeService()); if (entry.isEmpty()) { kError(30003) << KGlobal::mainComponent().componentName() << "part.desktop not found." << endl; kError(30003) << "Run 'kde4-config --path services' to see which directories were searched, assuming kde startup had the same environment as your current shell." << endl; kError(30003) << "Check your installation (did you install KOffice in a different prefix than KDE, without adding the prefix to /etc/kderc ?)" << endl; return false; } // Get the command line arguments which we have to parse KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); int argsCount = args->count(); KCmdLineArgs *koargs = KCmdLineArgs::parsedArgs("koffice"); QString dpiValues = koargs->getOption("dpi"); if (!dpiValues.isEmpty()) { int sep = dpiValues.indexOf(QRegExp("[x, ]")); int dpiX; int dpiY = 0; bool ok = true; if (sep != -1) { dpiY = dpiValues.mid(sep + 1).toInt(&ok); dpiValues.truncate(sep); } if (ok) { dpiX = dpiValues.toInt(&ok); if (ok) { if (!dpiY) dpiY = dpiX; KoGlobal::setDPI(dpiX, dpiY); } } } // No argument -> create an empty document if (!argsCount) { QString errorMsg; KoDocument* doc = entry.createDoc(&errorMsg); if (!doc) { if (!errorMsg.isEmpty()) KMessageBox::error(0, errorMsg); return false; } KoMainWindow *shell = new KoMainWindow(doc->componentData()); shell->show(); QObject::connect(doc, SIGNAL(sigProgress(int)), shell, SLOT(slotProgress(int))); // for initDoc to fill in the recent docs list // and for KoDocument::slotStarted doc->addShell(shell); if (doc->checkAutoSaveFile()) { shell->setRootDocument(doc); } else { doc->showStartUpWidget(shell); } // FIXME This needs to be moved someplace else QObject::disconnect(doc, SIGNAL(sigProgress(int)), shell, SLOT(slotProgress(int))); } else { const bool print = koargs->isSet("print"); const bool exportAsPdf = koargs->isSet("export-pdf"); QString pdfFileName = koargs->getOption("export-filename"); const bool doTemplate = koargs->isSet("template"); koargs->clear(); // Loop through arguments short int n = 0; // number of documents open short int nPrinted = 0; for (int i = 0; i < argsCount; i++) { // For now create an empty document QString errorMsg; KoDocument* doc = entry.createDoc(&errorMsg, 0); if (doc) { // show a shell asap KoMainWindow *shell = new KoMainWindow(doc->componentData()); shell->show(); // are we just trying to open a template? if (doTemplate) { QStringList paths; if (args->url(i).isLocalFile() && QFile::exists(args->url(i).toLocalFile())) { paths << QString(args->url(i).toLocalFile()); kDebug(30003) << "using full path..."; } else { QString desktopName(args->arg(i)); QString appName = KGlobal::mainComponent().componentName(); paths = KGlobal::dirs()->findAllResources("data", appName + "/templates/*/" + desktopName); if (paths.isEmpty()) { paths = KGlobal::dirs()->findAllResources("data", appName + "/templates/" + desktopName); } if (paths.isEmpty()) { KMessageBox::error(0L, i18n("No template found for: %1 ", desktopName)); delete shell; } else if (paths.count() > 1) { KMessageBox::error(0L, i18n("Too many templates found for: %1", desktopName)); delete shell; } } if (!paths.isEmpty()) { KUrl templateBase; templateBase.setPath(paths[0]); KDesktopFile templateInfo(paths[0]); QString templateName = templateInfo.readUrl(); KUrl templateURL; templateURL.setPath(templateBase.directory() + '/' + templateName); if (shell->openDocument(doc, templateURL)) { doc->resetURL(); doc->setEmpty(); doc->setTitleModified(); kDebug(30003) << "Template loaded..."; n++; } else { KMessageBox::error(0L, i18n("Template %1 failed to load.", templateURL.prettyUrl())); delete shell; } } // now try to load } else if (shell->openDocument(doc, args->url(i))) { if (print) { shell->slotFilePrint(); // delete shell; done by ~KoDocument nPrinted++; } else if (exportAsPdf) { KoPrintJob *job = shell->exportToPdf(pdfFileName); if (job) connect (job, SIGNAL(destroyed(QObject*)), shell, SLOT(slotFileQuit()), Qt::QueuedConnection); nPrinted++; } else { // Normal case, success n++; } } else { // .... if failed // delete doc; done by openDocument // delete shell; done by ~KoDocument } } } if (print || exportAsPdf) return nPrinted > 0; if (n == 0) // no doc, e.g. all URLs were malformed return false; } args->clear(); // not calling this before since the program will quit there. return true; }