예제 #1
0
파일: fhoicon.cpp 프로젝트: Slesa/launchy
QImage FhoIcon::getIconForFile(IShellFolder *psfParentItem, LPITEMIDLIST pidlChildItem) {
	HRESULT hres;
	IExtractIcon *pExtractIcon = NULL;

	hres = psfParentItem->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST *>(&pidlChildItem), IID_IExtractIcon, NULL, reinterpret_cast<LPVOID *>(&pExtractIcon));
	if (SUCCEEDED(hres)) {
		TCHAR str[MAX_PATH] = {0};
		int index;
		UINT flags;

		// Get the file location where the icons are stored.
		hres = pExtractIcon->GetIconLocation(0, str, MAX_PATH, &index, &flags);
		//hres = pExtractIcon->GetIconLocation(GIL_FORSHELL, str, MAX_PATH, &index, &flags);
		if (SUCCEEDED(hres)) {
            QString iconResourceFile = QString::fromWCharArray(str);
			
			// do not use 'general' getIconFromResource() -> ExtractIcon()!
			// use 'specific' pExtractIcon->Extract() instead!
			// this is because iconResourceFile returned may be "*" and not refer to a real file! pExtractIcon->Extract() will handle this, ExtractIcon() cannot handle this!
			// "*" is dangerous for caching the imageId! we could check if iconResourceFile refers to an existing file!?
			HICON hIconLarge = NULL;
			UINT nIconSize = MAKELONG(0, 0); // this requests the default size!?
			hres = pExtractIcon->Extract(str, index, &hIconLarge, NULL, nIconSize);
			if (hres == NOERROR) {
				if (hIconLarge) {
					QImage image = getIconFromHandle(hIconLarge);
				
					DestroyIcon(hIconLarge);

					return image;
				} else {
					return getIconFromResource(iconResourceFile, index);
				}
			} else {
				return getIconFromResource(iconResourceFile, index);
			}
		} else {
			return getIconForFile(pidlChildItem);
		}
		pExtractIcon->Release();
	} else {
		return getIconForFile(pidlChildItem);
	}
}
예제 #2
0
/*=========================================================================
  setPath 
=========================================================================*/
void KFileBrowser::setPath (const QString &_path)
  {
  QString path;
  if (_path != "")
    path = _path;
  else
    path = homeDir;

  QDir dir(path, "*", QDir::DirsFirst);
  if (dir.isReadable())
    {
    emit statusUpdate (tr("Scanning folder..."));
    list->clear();
    QStringList entries = dir.entryList();
    QStringList::ConstIterator it = entries.constBegin();
    int count = 0;
    while (it != entries.constEnd()) 
      {
      if (*it != "." && *it != "..")
        {
        QListWidgetItem *item = new QListWidgetItem(*it, list);
        item->setIcon (getIconForFile (path + "/" + *it));
        //QSize size (200, 50);
        //item->setSizeHint (size);
        count++;
        }
      ++it;
      }
    this->path = dir.canonicalPath();
    pathDisplay->setText (this->path);
    QString title;
    if (this->path == "/")
      title = tr("Files: ") + "/"; 
    else
      title = tr("Files: ") + QFileInfo(this->path).fileName();
    emit tabTitleChanged ((QWidget *)this, &title);
    setViewMode (viewMode);
    if (count == 0)
      emit statusUpdate (tr("Folder empty"));
    else if (count == 1)
      emit statusUpdate (QString::number (count) + " " + tr("item") 
        + " " + tr("in folder"));
    else
      emit statusUpdate (QString::number (count) + " " + tr("items") 
        + " " + tr("in folder"));
    }
   else
    {
    QMessageBox msgBox;
    msgBox.setIcon(QMessageBox::Critical);
    msgBox.setText("Can't read directory");
    msgBox.exec();
    }
  }
예제 #3
0
파일: fhoicon.cpp 프로젝트: Slesa/launchy
QImage FhoIcon::getIconForFile(LPCWSTR file, UINT basicFlags) {
	return getIconForFile(file, basicFlags, 0);
}
예제 #4
0
파일: fhoicon.cpp 프로젝트: Slesa/launchy
QImage FhoIcon::getIconForFile(QString fileName) {
	fileName = FhoEnv::expand(fileName);
    return getIconForFile((LPCWSTR)fileName.utf16(), 0);
}
예제 #5
0
파일: fhoicon.cpp 프로젝트: Slesa/launchy
QImage FhoIcon::getIconForExtension(QString fileExtension) {
	if (!fileExtension.startsWith('.')) {
		fileExtension = "." + fileExtension;
	}
    return getIconForFile((LPCWSTR)fileExtension.utf16(), SHGFI_USEFILEATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
}