Пример #1
0
bool Prj::create(const QString &path, QString *reason)
{
    try
    {
        QString absPath = QFileInfo(path).absoluteFilePath();

        // create path for icons
        if (!QDir(iconPath(absPath)).exists())
            if (!QDir().mkpath(iconPath(absPath)))
                throw tr("can't create path \"%1\"").arg(iconPath(absPath));
        // create path for screenshots
        if (!QDir(screenshotPath(absPath)).exists())
            if (!QDir().mkpath(screenshotPath(absPath)))
                throw tr("can't create path \"%1\"").arg(screenshotPath(absPath));
        // create path for downloads (webpages, e.t.c.)
        if (!QDir(downloadsPath(absPath)).exists())
            if (!QDir().mkpath(downloadsPath(absPath)))
                throw tr("can't create path \"%1\"").arg(downloadsPath(absPath));

        QFile file(xmlPath(path));
        if (!file.open(QIODevice::WriteOnly))
            throw file.errorString();

        // write empty xml document
        return PrjXml::saveEmptyXml(&file, reason);
    }
    catch (const QString &error)
    {
        if (reason) *reason = error;
    }

    return false;
}
Пример #2
0
// cf. http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx
static bool WriteExtendedFileExtensionInfo(HKEY hkey)
{
    bool success = true;

    ScopedMem<WCHAR> exePath(GetInstalledExePath());
    if (HKEY_LOCAL_MACHINE == hkey)
        success &= WriteRegStr(hkey, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" EXENAME, NULL, exePath);

    // mirroring some of what DoAssociateExeWithPdfExtension() does (cf. AppTools.cpp)
    ScopedMem<WCHAR> iconPath(str::Join(exePath, L",1"));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\DefaultIcon", NULL, iconPath);
    ScopedMem<WCHAR> cmdPath(str::Format(L"\"%s\" \"%%1\" %%*", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Open\\Command", NULL, cmdPath);
    ScopedMem<WCHAR> printPath(str::Format(L"\"%s\" -print-to-default \"%%1\"", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Print\\Command", NULL, printPath);
    ScopedMem<WCHAR> printToPath(str::Format(L"\"%s\" -print-to \"%%2\" \"%%1\"", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\PrintTo\\Command", NULL, printToPath);
    // don't add REG_CLASSES_APPS L"\\SupportedTypes", as that prevents SumatraPDF.exe to
    // potentially appear in the Open With lists for other filetypes (such as single images)

    // add the installed SumatraPDF.exe to the Open With lists of the supported file extensions
    for (int i = 0; NULL != gSupportedExts[i]; i++) {
        ScopedMem<WCHAR> keyname(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" EXENAME));
        success &= CreateRegKey(hkey, keyname);
        // TODO: stop removing this after version 1.8 (was wrongly created for version 1.6)
        keyname.Set(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" APP_NAME_STR));
        DeleteRegKey(hkey, keyname);
    }

    // in case these values don't exist yet (we won't delete these at uninstallation)
    success &= WriteRegStr(hkey, REG_CLASSES_PDF, L"Content Type", L"application/pdf");
    success &= WriteRegStr(hkey, L"Software\\Classes\\MIME\\Database\\Content Type\\application/pdf", L"Extension", L".pdf");

    return success;
}
Пример #3
0
void FileSystem::setConfiguration(QDomDocument* config, const QString& mainDataDir, const QString& userDataDir)
{
    Q_UNUSED(mainDataDir);
    Q_UNUSED(userDataDir);

    QString rootPath;
    QIcon folderIcon;
    QIcon defaultFileIcon;
    QHash<QString, QIcon> icons;
    if (config != NULL) {
        QDomElement elt = config->documentElement();
        if (!elt.isNull() && elt.tagName() == "FileSystem") {
            for (QDomNode n = elt.firstChild(); !n.isNull(); n = n.nextSibling()) {
                if (n.isElement()) {
                    QDomElement e = n.toElement();
                    if (e.tagName() == "RootPath") {
                        QString p(e.attribute("value"));
                        if (QFile::exists(p)) {
                            rootPath = p;
                        }
                    }
                    if (e.tagName() == "Icons") {
                        for (QDomNode n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling()) {
                            if (n2.isElement()) {
                                QDomElement e2 = n2.toElement();
                                QString iconName(e2.attribute("icon"));
                                QString iconPath(userDataDir + "/" + iconName);
                                if (!QFile::exists(iconPath)) {
                                    iconPath = mainDataDir + "/" + iconName;
                                    if (!QFile::exists(iconPath)) {
                                        iconPath = QString::null;
                                    }
                                }
                                if (e2.tagName() == "Folder") {
                                    folderIcon = QIcon(iconPath);
                                } else if (e2.tagName() == "DefaultFile") {
                                    defaultFileIcon = QIcon(iconPath);
                                } else if (e2.tagName() == "File") {
                                    icons[e2.attribute("type")] = QIcon(iconPath);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (rootPath.isEmpty()) {
        rootPath = QDir::rootPath();
    }
    MediaIconProvider* iconProvider = new MediaIconProvider();
    iconProvider->setFolderIcon(folderIcon);
    iconProvider->setDefaultFileIcon(defaultFileIcon);
    iconProvider->setFileTypeIcons(icons);
    m_model->setIconProvider(iconProvider);
    m_model->setRootPath(rootPath);
}
Пример #4
0
Drink::Drink(QObject *parent) :
    QObject(parent),
    m_type(UnkownType),
    m_volume(0.0),
    m_alcoholByVolume(0.0),
    m_liveDrinks(QpRelation(&Drink::liveDrinks))
{
    setPicture(QPixmap(iconPath()));
}
Пример #5
0
void                MainWindow::afficherPokemonDetails(QListWidgetItem *current, QListWidgetItem *previous)
{
    DPokemon        p;
    QString         *filename = new QString(":/Pokemons/ressources/");
    int             idx;

    p.setName(current->text().toUpper());
    idx = this->pokemons->indexOf(p);
    p = pokemons->at(idx);
    filename->append(p.getId());
    filename->append(QString(".gif"));
    ui->pokemonName->setText(p.getName().toLower());
    ui->pokemonIcon->setPixmap(QPixmap(*filename));
    ui->pokemonId->setText(p.getId());
    ui->pokemonType->setText(p.getType());
    ui->pokemonAbility->setText(p.getAbility());
    ui->pokemonExp->setText(p.getExp());
    ui->pokemonRatio->setText(p.getRatio());
    ui->pokemonEggGroup->setText(p.getEggGroup());
    ui->pokemonSpecies->setText(p.getSpecies());
    ui->pokemonHeight->setText(p.getHeight());
    ui->pokemonWeight->setText(p.getWeight());
    ui->pokemonDescription->setText(p.getDescription());
    ui->moveList->clear();
    QList<Move> m(p.getMove());
    for (int i = 0; i < m.count(); i++)
    {
        QString item("");
        if (m[i].getLvl() != "")
        {
            item.append("Lv.");
            item.append(m[i].getLvl());
            item.append(" ");
        }
        item.append(m[i].getName());
        ui->moveList->addItem(item);
    }
    ui->evoList->clear();
    QList<Evo> e(p.getEvo());
    for (int i = 0; i < e.count(); i++)
    {
        QString pokemonDetails("");
        QString iconPath(":/Pokemons/ressources/");
        iconPath.append(e[i].getId());
        iconPath.append(".gif");
        if (e[i].getLvl() != "")
        {
            pokemonDetails.append("Lv.");
            pokemonDetails.append(e[i].getLvl());
            pokemonDetails.append(" ");
        }
        pokemonDetails.append(e[i].getName());
        ui->evoList->addItem(new QListWidgetItem(QIcon(iconPath), pokemonDetails));
    }
}
Пример #6
0
QgsDashSpaceDialog::QgsDashSpaceDialog( const QVector<qreal>& v, QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f )
{
  setupUi( this );

  mAddButton->setIcon( QIcon( iconPath( "symbologyAdd.svg" ) ) );
  mRemoveButton->setIcon( QIcon( iconPath( "symbologyRemove.svg" ) ) );

  double dash = 0;
  double space = 0;
  for ( int i = 0; i < ( v.size() - 1 ); ++i )
  {
    dash = v.at( i );
    ++i;
    space = v.at( i );
    QTreeWidgetItem* entry = new QTreeWidgetItem();
    entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
    entry->setText( 0, QString::number( dash ) );
    entry->setText( 1, QString::number( space ) );
    mDashSpaceTreeWidget->addTopLevelItem( entry );
  }
}
Пример #7
0
//TODO: this is kind of funky; a launchpoint of an app should really just present the info for the app.
json_object* LaunchPoint::toJSON() const
{
	json_object* json = json_object_new_object();
	json_object_object_add(json, (char*) "id",   json_object_new_string((char*) id().c_str()));
	if (m_appDesc) {
		json_object_object_add(json, (char*) "version", json_object_new_string(m_appDesc->version().c_str()));
		json_object_object_add(json, (char*) "appId", json_object_new_string((char*) m_appDesc->id().c_str()));
		json_object_object_add(json, (char*) "vendor", json_object_new_string((char*) m_appDesc->vendorName().c_str()));
		json_object_object_add(json, (char*) "vendorUrl", json_object_new_string((char *) m_appDesc->vendorUrl().c_str()));
		int appSize = 0;
		std::string packageId = m_appDesc->id();
		if (this->isDefault()) {
			PackageDescription* packageDesc = ApplicationManager::instance()->getPackageInfoByAppId(m_appDesc->id());
			if (packageDesc) {
				appSize = packageDesc->packageSize();
				packageId = packageDesc->id();
			}

		}
		json_object_object_add(json, (char*) "size", json_object_new_int(appSize));
		json_object_object_add(json, (char*) "packageId", json_object_new_string((char*) packageId.c_str()));

		if (m_appDesc->dockModeStatus()) {
			json_object_object_add(json, (char*) "exhibitionMode", json_object_new_boolean(true));
			json_object_object_add(json, (char*) "exhibitionModeTitle", json_object_new_string((char*)m_appDesc->dockModeTitle().c_str()));
		}
	} else {
		json_object_object_add(json, (char*) "size", json_object_new_int(0));
		json_object_object_add(json, (char*) "packageId", json_object_new_string((char*) m_appDesc->id().c_str()));
	}
	json_object_object_add(json, (char*) "removable", json_object_new_boolean(m_removable));

	json_object_object_add(json, (char*) "launchPointId", json_object_new_string((char*) launchPointId().c_str()));
	json_object_object_add(json, (char*) "title", json_object_new_string((char*) title().c_str()));
	json_object_object_add(json, (char*) "appmenu", json_object_new_string((char*)menuName().c_str()));
	json_object_object_add(json, (char*) "icon", json_object_new_string((char*) iconPath().c_str()));

	if (!params().empty() && m_appDesc->type() != ApplicationDescription::Type_Qt) {
        if (m_appDesc->type() == ApplicationDescription::Type_Qt) {
            json_object_object_add(json, (char*) "params", json_object_new_string(params().c_str()));
        }
        else {
    		json_object* paramsJson = json_tokener_parse(params().c_str());
	    	json_object_object_add(json, (char*) "params", paramsJson);
        }
	}

	return json;
}
Пример #8
0
// cf. http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx
static bool WriteExtendedFileExtensionInfo(HKEY hkey)
{
    bool ok = true;

    ScopedMem<WCHAR> exePath(GetInstalledExePath());
    if (HKEY_LOCAL_MACHINE == hkey)
        ok &= WriteRegStr(hkey, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" EXENAME, nullptr, exePath);

    // mirroring some of what DoAssociateExeWithPdfExtension() does (cf. AppTools.cpp)
    ScopedMem<WCHAR> iconPath(str::Join(exePath, L",1"));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\DefaultIcon", nullptr, iconPath);
    ScopedMem<WCHAR> cmdPath(str::Format(L"\"%s\" \"%%1\" %%*", exePath));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Open\\Command", nullptr, cmdPath);
    ScopedMem<WCHAR> printPath(str::Format(L"\"%s\" -print-to-default \"%%1\"", exePath));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Print\\Command", nullptr, printPath);
    ScopedMem<WCHAR> printToPath(str::Format(L"\"%s\" -print-to \"%%2\" \"%%1\"", exePath));
    ok &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\PrintTo\\Command", nullptr, printToPath);
    // don't add REG_CLASSES_APPS L"\\SupportedTypes", as that prevents SumatraPDF.exe to
    // potentially appear in the Open With lists for other filetypes (such as single images)

    // add the installed SumatraPDF.exe to the Open With lists of the supported file extensions
    // TODO: per http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx we shouldn't be
    // using OpenWithList but OpenWithProgIds. Also, it doesn't seem to work on my win7 32bit
    // (HKLM\Software\Classes\.mobi\OpenWithList\SumatraPDF.exe key is present but "Open With"
    // menu item doesn't even exist for .mobi files
    // It's not so easy, though, because if we just set it to SumatraPDF,
    // all gSupportedExts will be reported as "PDF Document" by Explorer, so this needs
    // to be more intelligent. We should probably mimic Windows Media Player scheme i.e.
    // set OpenWithProgIds to SumatraPDF.AssocFile.Mobi etc. and create apropriate
    // \SOFTWARE\Classes\CLSID\{GUID}\ProgID etc. entries
    // Also, if Sumatra is the only program handling those docs, our
    // PDF icon will be shown (we need icons and properly configure them)
    for (int i = 0; nullptr != gSupportedExts[i]; i++) {
        ScopedMem<WCHAR> keyname(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" EXENAME));
        ok &= CreateRegKey(hkey, keyname);
    }

    // in case these values don't exist yet (we won't delete these at uninstallation)
    ok &= WriteRegStr(hkey, REG_CLASSES_PDF, L"Content Type", L"application/pdf");
    ok &= WriteRegStr(hkey, L"Software\\Classes\\MIME\\Database\\Content Type\\application/pdf", L"Extension", L".pdf");

    return ok;
}
Пример #9
0
bool Prj::open(const QString &path, QString *reason)
{
    try
    {
        if (isOpen())
            throw tr("bookmarks collection is already opened");

        QFile file(xmlPath(path));
        if (!file.open(QIODevice::ReadOnly))
            throw file.errorString();

        blockSignals(true);
        bool state = PrjXml::loadXml(m_manager, &file, reason);
        blockSignals(false);
        if (!state)
            return false;

        m_path = path;
        m_hasChanges = false;

        QList<QUrl> urls;
        foreach (BookmarkItem *item, m_manager->bookmarkMgr()->bookmarks())
            urls.push_back(item->data().url());
        m_iconMgr->setIconsPath(iconPath());
        m_iconMgr->loadIcons(urls);

        updateActions();
        emit opened();

        return true;
    }
    catch (const QString &error)
    {
        if (reason) *reason = error;
    }

    return false;
}
Пример #10
0
NS_IMETHODIMP
nsMozIconURI::SetSpec(const nsACString &aSpec)
{
  // Reset everything to default values.
  mIconURL = nsnull;
  mSize = DEFAULT_IMAGE_SIZE;
  mContentType.Truncate();
  mFileName.Truncate();
  mStockIcon.Truncate();
  mIconSize = -1;
  mIconState = -1;

  nsCAutoString iconSpec(aSpec);
  if (!Substring(iconSpec, 0, MOZICON_SCHEME_LEN).EqualsLiteral(MOZICON_SCHEME))
    return NS_ERROR_MALFORMED_URI;

  PRInt32 questionMarkPos = iconSpec.Find("?");
  if (questionMarkPos != -1 && static_cast<PRInt32>(iconSpec.Length()) > (questionMarkPos + 1))
  {
    extractAttributeValue(iconSpec.get(), "contentType=", mContentType);

    nsCAutoString sizeString;
    extractAttributeValue(iconSpec.get(), "size=", sizeString);
    if (!sizeString.IsEmpty())
    {      
      const char *sizeStr = sizeString.get();
      for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kSizeStrings); i++)
      {
        if (PL_strcasecmp(sizeStr, kSizeStrings[i]) == 0)
        {
          mIconSize = i;
          break;
        }
      }

      PRInt32 sizeValue = atoi(sizeString.get());
      if (sizeValue)
        mSize = sizeValue;
    }

    nsCAutoString stateString;
    extractAttributeValue(iconSpec.get(), "state=", stateString);
    if (!stateString.IsEmpty())
    {
      const char *stateStr = stateString.get();
      for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kStateStrings); i++)
      {
        if (PL_strcasecmp(stateStr, kStateStrings[i]) == 0)
        {
          mIconState = i;
          break;
        }
      }
    }
  }

  PRInt32 pathLength = iconSpec.Length() - MOZICON_SCHEME_LEN;
  if (questionMarkPos != -1)
    pathLength = questionMarkPos - MOZICON_SCHEME_LEN;
  if (pathLength < 3)
    return NS_ERROR_MALFORMED_URI;

  nsCAutoString iconPath(Substring(iconSpec, MOZICON_SCHEME_LEN, pathLength));

  // Icon URI path can have three forms:
  // (1) //stock/<icon-identifier>
  // (2) //<some dummy file with an extension>
  // (3) a valid URL

  if (!strncmp("//stock/", iconPath.get(), 8))
  {
    mStockIcon.Assign(Substring(iconPath, 8));
    // An icon identifier must always be specified.
    if (mStockIcon.IsEmpty())
      return NS_ERROR_MALFORMED_URI;
    return NS_OK;
  }

  if (StringBeginsWith(iconPath, NS_LITERAL_CSTRING("//")))
  {
    // Sanity check this supposed dummy file name.
    if (iconPath.Length() > SANE_FILE_NAME_LEN)
      return NS_ERROR_MALFORMED_URI;
    iconPath.Cut(0, 2);
    mFileName.Assign(iconPath);
  }

  nsresult rv;
  nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIURI> uri;
  ioService->NewURI(iconPath, nsnull, nsnull, getter_AddRefs(uri));
  mIconURL = do_QueryInterface(uri);
  if (mIconURL)
    mFileName.Truncate();
  else if (mFileName.IsEmpty())
    return NS_ERROR_MALFORMED_URI;

  return NS_OK;
}