void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) const { std::string name = this->name(); ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") ->GetGroup("Workbench"); // workbench specific custom toolbars if (hGrp->HasGroup(name.c_str())) { hGrp = hGrp->GetGroup(name.c_str()); if (hGrp->HasGroup(toolbar)) { hGrp = hGrp->GetGroup(toolbar); setupCustomToolbars(root, hGrp); } } // for this workbench global toolbars are not allowed if (getTypeId() == NoneWorkbench::getClassTypeId()) return; // application-wide custom toolbars hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") ->GetGroup("Workbench"); if (hGrp->HasGroup("Global")) { hGrp = hGrp->GetGroup("Global"); if (hGrp->HasGroup(toolbar)) { hGrp = hGrp->GetGroup(toolbar); setupCustomToolbars(root, hGrp); } } }
void DlgCustomToolbars::importCustomToolbars(const QByteArray& name) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench"); const char* subgroup = (type == Toolbar ? "Toolbar" : "Toolboxbar"); if (!hGrp->HasGroup(name.constData())) return; hGrp = hGrp->GetGroup(name.constData()); if (!hGrp->HasGroup(subgroup)) return; hGrp = hGrp->GetGroup(subgroup); std::string separator = "Separator"; std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) { // create a toplevel item QTreeWidgetItem* toplevel = new QTreeWidgetItem(toolbarTreeWidget); bool active = (*it)->GetBool("Active", true); toplevel->setCheckState(0, (active ? Qt::Checked : Qt::Unchecked)); // get the elements of the subgroups std::vector<std::pair<std::string,std::string> > items = (*it)->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) { // since we have stored the separators to the user parameters as (key, pair) we had to // make sure to use a unique key because otherwise we cannot store more than // one. if (it2->first.substr(0, separator.size()) == separator) { QTreeWidgetItem* item = new QTreeWidgetItem(toplevel); item->setText(0, tr("<Separator>")); item->setData(0, Qt::UserRole, QByteArray("Separator")); item->setSizeHint(0, QSize(32, 32)); } else if (it2->first == "Name") { QString toolbarName = QString::fromUtf8(it2->second.c_str()); toplevel->setText(0, toolbarName); } else { Command* pCmd = rMgr.getCommandByName(it2->first.c_str()); if (pCmd) { // command name QTreeWidgetItem* item = new QTreeWidgetItem(toplevel); item->setText(0, qApp->translate(pCmd->className(), pCmd->getMenuText())); item->setData(0, Qt::UserRole, QByteArray(it2->first.c_str())); if (pCmd->getPixmap()) item->setIcon(0, BitmapFactory().iconFromTheme(pCmd->getPixmap())); item->setSizeHint(0, QSize(32, 32)); } } } } }
void DlgCustomToolbars::exportCustomToolbars(const QByteArray& workbench) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench"); const char* subgroup = (type == Toolbar ? "Toolbar" : "Toolboxbar"); hGrp = hGrp->GetGroup(workbench.constData())->GetGroup(subgroup); hGrp->Clear(); CommandManager& rMgr = Application::Instance->commandManager(); for (int i=0; i<toolbarTreeWidget->topLevelItemCount(); i++) { QTreeWidgetItem* toplevel = toolbarTreeWidget->topLevelItem(i); QString groupName = QString::fromLatin1("Custom_%1").arg(i+1); QByteArray toolbarName = toplevel->text(0).toUtf8(); ParameterGrp::handle hToolGrp = hGrp->GetGroup(groupName.toLatin1()); hToolGrp->SetASCII("Name", toolbarName.constData()); hToolGrp->SetBool("Active", toplevel->checkState(0) == Qt::Checked); // since we store the separators to the user parameters as (key, pair) we must // make sure to use a unique key because otherwise we cannot store more than // one. int suffixSeparator = 1; for (int j=0; j<toplevel->childCount(); j++) { QTreeWidgetItem* child = toplevel->child(j); QByteArray commandName = child->data(0, Qt::UserRole).toByteArray(); if (commandName == "Separator") { QByteArray key = commandName + QByteArray::number(suffixSeparator); suffixSeparator++; hToolGrp->SetASCII(key, commandName); } else { Command* pCmd = rMgr.getCommandByName(commandName); if (pCmd) { hToolGrp->SetASCII(pCmd->getName(), pCmd->getAppModuleName()); } } } } }
void DlgParameterImp::showEvent(QShowEvent* ) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences"); hGrp = hGrp->GetGroup("ParameterEditor"); std::string buf = hGrp->GetASCII("Geometry", ""); if (!buf.empty()) { int x1, y1, x2, y2; char sep; std::stringstream str(buf); str >> sep >> x1 >> sep >> y1 >> sep >> x2 >> sep >> y2; QRect rect; rect.setCoords(x1, y1, x2, y2); this->setGeometry(rect); }
void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) const { std::string name = this->name(); ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") ->GetGroup("Workbench")->GetGroup(name.c_str())->GetGroup(toolbar); std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) { bool active = (*it)->GetBool("Active", true); if (!active) // ignore this toolbar continue; ToolBarItem* bar = new ToolBarItem(root); bar->setCommand("Custom"); // get the elements of the subgroups std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup((*it)->GetGroupName())->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) { if (it2->first == "Separator") { *bar << "Separator"; } else if (it2->first == "Name") { bar->setCommand(it2->second); } else { Command* pCmd = rMgr.getCommandByName(it2->first.c_str()); if (!pCmd) { // unknown command // try to find out the appropriate module name std::string pyMod = it2->second + "Gui"; try { Base::Interpreter().loadModule(pyMod.c_str()); } catch(const Base::Exception&) { } // Try again pCmd = rMgr.getCommandByName(it2->first.c_str()); } if (pCmd) { *bar << it2->first; // command name } } } } }
void MacroCommand::save() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Macro")->GetGroup("Macros"); hGrp->Clear(); std::vector<Command*> macros = Application::Instance->commandManager().getGroupCommands("Macros"); if ( macros.size() > 0 ) { for (std::vector<Command*>::iterator it = macros.begin(); it!=macros.end(); ++it ) { MacroCommand* macro = (MacroCommand*)(*it); ParameterGrp::handle hMacro = hGrp->GetGroup(macro->getName()); hMacro->SetASCII( "Script", macro->getScriptName () ); hMacro->SetASCII( "Menu", macro->getMenuText () ); hMacro->SetASCII( "Tooltip", macro->getToolTipText() ); hMacro->SetASCII( "WhatsThis", macro->getWhatsThis () ); hMacro->SetASCII( "Statustip", macro->getStatusTip () ); hMacro->SetASCII( "Pixmap", macro->getPixmap () ); hMacro->SetASCII( "Accel", macro->getAccel () ); } } }
void Workbench::setupCustomShortcuts() const { // Assigns user defined accelerators ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter(); if (hGrp->HasGroup("Shortcut")) { hGrp = hGrp->GetGroup("Shortcut"); // Get all user defined shortcuts const CommandManager& cCmdMgr = Application::Instance->commandManager(); std::vector<std::pair<std::string,std::string> > items = hGrp->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it = items.begin(); it != items.end(); ++it) { Command* cmd = cCmdMgr.getCommandByName(it->first.c_str()); if (cmd && cmd->getAction()) { // may be UTF-8 encoded QString str = QString::fromUtf8(it->second.c_str()); QKeySequence shortcut = str; cmd->getAction()->setShortcut(shortcut.toString(QKeySequence::NativeText)); } } } }
void MacroCommand::load() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Macro"); if (hGrp->HasGroup("Macros")) { hGrp = hGrp->GetGroup("Macros"); std::vector<Base::Reference<ParameterGrp> > macros = hGrp->GetGroups(); for (std::vector<Base::Reference<ParameterGrp> >::iterator it = macros.begin(); it!=macros.end(); ++it ) { MacroCommand* macro = new MacroCommand((*it)->GetGroupName()); macro->setScriptName ( (*it)->GetASCII( "Script" ).c_str() ); macro->setMenuText ( (*it)->GetASCII( "Menu" ).c_str() ); macro->setToolTipText ( (*it)->GetASCII( "Tooltip" ).c_str() ); macro->setWhatsThis ( (*it)->GetASCII( "WhatsThis" ).c_str() ); macro->setStatusTip ( (*it)->GetASCII( "Statustip" ).c_str() ); if ((*it)->GetASCII("Pixmap", "nix") != "nix") macro->setPixmap ( (*it)->GetASCII( "Pixmap" ).c_str() ); macro->setAccel ( (*it)->GetASCII( "Accel",0 ).c_str() ); Application::Instance->commandManager().addCommand( macro ); } } }
void StdCmdDownloadOnlineHelp::activated(int iMsg) { if (!wget->isDownloading()) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp"); hGrp = hGrp->GetGroup("Preferences")->GetGroup("OnlineHelp"); std::string url = hGrp->GetASCII("DownloadURL", "www.freecadweb.org/wiki/"); std::string prx = hGrp->GetASCII("ProxyText", ""); bool bUseProxy = hGrp->GetBool ("UseProxy", false); bool bAuthor = hGrp->GetBool ("Authorize", false); if (bUseProxy) { QString username = QString::null; QString password = QString::null; if (bAuthor) { QDialog dlg(getMainWindow()); dlg.setModal(true); Ui_DlgAuthorization ui; ui.setupUi(&dlg); if (dlg.exec() == QDialog::Accepted) { username = ui.username->text(); password = ui.password->text(); } } wget->setProxy(QString::fromAscii(prx.c_str()), username, password); } int loop=3; bool canStart = false; // set output directory QString path = QString::fromUtf8(App::GetApplication().GetHomePath()); path += QString::fromAscii("/doc/"); ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/OnlineHelp"); path = QString::fromUtf8(hURLGrp->GetASCII( "DownloadLocation", path.toAscii() ).c_str()); while (loop > 0) { loop--; QFileInfo fi( path); if (!fi.exists()) { if (QMessageBox::critical(getMainWindow(), tr("Non-existing directory"), tr("The directory '%1' does not exist.\n\n" "Do you want to specify an existing directory?").arg(fi.filePath()), QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape) != QMessageBox::Yes) { // exit the command return; } else { path = FileDialog::getExistingDirectory(); if ( path.isEmpty() ) return; } } if (!fi.permission( QFile::WriteUser)) { if (QMessageBox::critical(getMainWindow(), tr("Missing permission"), tr("You don't have write permission to '%1'\n\n" "Do you want to specify another directory?").arg(fi.filePath()), QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape) != QMessageBox::Yes) { // exit the command return; } else { path = FileDialog::getExistingDirectory(); if ( path.isEmpty() ) return; } } else { wget->setOutputDirectory( path ); canStart = true; break; } } if (canStart) { bool ok = wget->startDownload(QString::fromAscii(url.c_str())); if ( ok == false ) Base::Console().Error("The tool 'wget' couldn't be found. Please check your installation."); else if ( wget->isDownloading() && _pcAction ) _pcAction->setText(tr("Stop downloading")); } } else // kill the process now { wget->abort(); } }