1

デバイスにインストールされているすべてのアプリケーションの名前とそのアイコンを使用してQListWidgetを作成するQtアプリケーションを使用しています。そのため、このLINKのコードから、各アプリケーションのすべてのアプリケーション名とUIDを取得できませんでした。しかし、アプリケーションアイコンも取得できませんでした。このLINK1LINK2の両方を試しましたが、ここで、CGulIconをQIconに、CApaMaskedBitmapをQIconに変換する方法など、さらにいくつかの問題に遭遇しました。

これどうやってするの?

4

2 に答える 2

2

解決策が得られない場合、または疑問がある場合は、ここをクリックして議論してください。

main.cpp

#include "GetInstalledApps.h"

#include <QtGui>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    GetInstalledApps w;
    w.showMaximized();
    return a.exec();
}

。プロ

TEMPLATE = app
TARGET = GetInstalledApps 

QT        += core \
    gui 

HEADERS   += GetInstalledApps.h
SOURCES   += main.cpp \
    GetInstalledApps.cpp
FORMS     += GetInstalledApps.ui
RESOURCES +=

HEADERS += xqinstaller_p.h \
   xqinstaller.h \

SOURCES += xqinstaller_p.cpp \
   xqinstaller.cpp

symbian:LIBS += -lswinstcli \
   -lcommdb \
   -lapparc \
   -lefsrv \
   -lapgrfx \


symbian:TARGET.CAPABILITY += TrustedUI
symbian:TARGET.UID3 = 0xEF3055F4

GetInstalledApps.h

#ifndef GETINSTALLEDAPPS_H
#define GETINSTALLEDAPPS_H

#include <QtGui/QMainWindow>
#include "ui_GetInstalledApps.h"
#include "xqinstaller.h"

class GetInstalledApps : public QMainWindow
{
    Q_OBJECT

public:
    GetInstalledApps(QWidget *parent = 0);
    ~GetInstalledApps();

private:
    void GetApps();
    
private:
    Ui::GetInstalledAppsClass ui;
    XQInstaller* m_installer;
    QMap<QString, uint> m_applications;
    QList<QString> m_appNames;
    QList<uint> m_appUID;
};

#endif // GETINSTALLEDAPPS_H

GetInstalledApps.cpp

#include "GetInstalledApps.h"
#include <QScrollArea>

GetInstalledApps::GetInstalledApps(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    setWindowTitle("GetAllInstalledApps");
    m_installer = new XQInstaller(this);
    GetApps();
    
}

void GetInstalledApps::GetApps()
{
    /* Get List of applications. 
     * type of m_applications is QMap<QString, uint>.
     * type of  m_installer is XQInstaller
     */
    m_applications = m_installer->applications();
    
    /* Get List of application names
     type of m_appNames is QList<QString> */
    m_appNames = m_applications.keys(); 
    
    /* Get List of application UID in decimal. 
    type of m_appUID is QList<uint> */
    m_appUID = m_applications.values(); 
    
    ui.listWidget->clear();
    for (int i = 0; i < m_appNames.count(); i++) 
    {
        QString str;
        /* convert UID from decimal to hex and then string. */
        str.setNum(m_appUID.at(i),16);
        /* append name and UID to string */     
        QString string(m_appNames.at(i)+"  UID:"+ str);
        /* append string to list widget to display on screen */
        ui.listWidget->addItem(string);
    }
    
    /* Let's make the UI scale so that we can scroll it. */
    QScrollArea* scrollArea = new QScrollArea;
    scrollArea->setWidget(ui.listWidget);
    scrollArea->setWidgetResizable(true);

    setCentralWidget(scrollArea);
}

GetInstalledApps::~GetInstalledApps()
{

}

xqinstaller.h

#ifndef XQINSTALLER_H
#define XQINSTALLER_H

// INCLUDES
#include <QObject>
#include <QMap>

class XQInstallerPrivate;

// CLASS DECLARATION
class XQInstaller : public QObject
{
    Q_OBJECT

public:
    enum Error {
        NoError = 0,
        OutOfMemoryError,
        AlreadyInUseError,
        UserCancelError, 
        PackageNotSupportedError,
        SecurityFailureError,
        MissingDependencyError,
        NoRightsError,
        BusyError,
        AccessDeniedError,
        UpgradeError,
        UnknownError = -1
    };
    
    enum Drive {
        DriveA,   DriveB,   DriveC,   DriveD,   DriveE,
        DriveF,   DriveG,   DriveH,   DriveI,   DriveJ,
        DriveK,   DriveL,   DriveM,   DriveN,   DriveO, 
        DriveP,   DriveQ,   DriveR,   DriveS,   DriveT,
        DriveU,   DriveV,   DriveW,   DriveX,   DriveY,
        DriveZ
    };

    XQInstaller(QObject *parent = 0);
    ~XQInstaller();
    
    bool install(const QString& file, XQInstaller::Drive drive = XQInstaller::DriveC);
    QMap<QString, uint> applications() const;
    bool remove(uint uid);

    XQInstaller::Error error() const;
    
Q_SIGNALS:
    void applicationInstalled();
    void applicationRemoved();
    void error(XQInstaller::Error);
    
private:
    friend class XQInstallerPrivate;
    XQInstallerPrivate *d;
};

#endif // XQINSTALLER_H

xqinstaller.cpp

#include "xqinstaller.h"
#include "xqinstaller_p.h"

/*!
    \class XQInstaller
    \brief The XQInstaller class is used to install sis-packages silently. 
    This extension can be used for example to install back-end applications.

    Example:
    \code
    XQInstaller *installer = new XQInstaller(this);
    QMap<QString, uint> applications = installer->applications();
    QListWidget *applicationList = new QListWidget(this);
    QList<QString> appNames = applications.keys();
    for (int i = 0; i < appNames.count(); i++) {
        applicationList->addItem(appNames.at(i));
    }   
    \endcode
*/

/*!
    Constructs a XQInstaller object with the given parent.
    \sa install(), remove()
*/
XQInstaller::XQInstaller(QObject *parent)
    : QObject(parent), d(new XQInstallerPrivate(this))
{
}

/*!
    Destroys the XQInstaller object.
*/
XQInstaller::~XQInstaller()
{
    delete d;
}

/*!
    Installs a sis package silently given as parameter.

    \param file Sis package
    \param drive Drive letter where the sis is installed to. Default value is 'C'.
    \return If false is returned, an error has occurred. Call error() to get a value of 
    XQInstaller::Error that indicates which error occurred
    \sa error()
*/  
bool XQInstaller::install(const QString& file, XQInstaller::Drive drive)
{
    return d->install(file, drive);
}

/*!
    Get list of installed applications
    If an empty QMap is returned, an error has possibly occurred. Call error() to get a value of 
    XQInstaller::Error that indicates which error occurred if any
    
    \return List of installed applications
    \sa error()
*/
QMap<QString, uint> XQInstaller::applications() const
{
    return d->applications();
}

/*!
    Removes application specified by the uid
   
    \param uid of the application
    \return True if removing was successfully started, otherwise false
    \sa error()
*/
bool XQInstaller::remove(uint uid)
{
    return d->remove(uid);
}

/*!
    \enum XQInstaller::Error

    This enum defines the possible errors for a XQInstaller object.
*/
/*! \var XQInstaller::Error XQInstaller::NoError
    No error occured.
*/
/*! \var XQInstaller::Error XQInstaller::OutOfMemoryError
    Not enough memory.
*/
/*! \var XQInstaller::Error XQInstaller::AlreadyInUseError
    Installer is already in used.
*/
/*! \var XQInstaller::Error XQInstaller::UserCancelError
    Installer cancelled by the user.
*/
/*! \var XQInstaller::Error XQInstaller::PackageNotSupportedError
    Package not supported
*/
/*! \var XQInstaller::Error XQInstaller::SecurityFailureError
    Security failure
*/
/*! \var XQInstaller::Error XQInstaller::MissingDependencyError
    Missing dependency
*/
/*! \var XQInstaller::Error XQInstaller::NoRightsError
    No rights
*/
/*! \var XQInstaller::Error XQInstaller::BusyError
    Installer is busy
*/
/*! \var XQInstaller::Error XQInstaller::AccessDeniedError
    Access denied
*/
/*! \var XQInstaller::Error XQInstaller::UpgradeError
    Error while upgrading
*/
/*! \var XQInstaller::Error XQInstaller::UnknownError
    Unknown error.
*/

/*!
    Returns the type of error that occurred if the latest function call failed; otherwise returns NoError
    \return Error code
*/
XQInstaller::Error XQInstaller::error() const
{
    return d->error();
}

/*!
    \fn void XQInstaller::applicationInstalled()

    This signal is emitted when the application has been installed.

    \sa install()
*/

/*!
    \fn void XQInstaller::error(XQInstaller::Error)

    This signal is emitted if error occured during the asynchronous operation

    \sa install()
*/

/*!
    \fn void XQInstaller::applicationRemoved()

    This signal is emitted when the application has been removed.

    \sa remove()
*/

// End of file

xqinstaller_h.h

#ifndef XQINSTALLER_P_H
#define XQINSTALLER_P_H

// INCLUDES
#include "xqinstaller.h"
#include <SWInstApi.h>
#include <SWInstDefs.h>

// FORWARD DECLARATIONS
class QString;
class QFile;

// CLASS DECLARATION
class XQInstallerPrivate: public CActive
{

public:
    enum State {
        ERemove,
        EInstall
    };
    
    XQInstallerPrivate(XQInstaller *installer);
    ~XQInstallerPrivate();
    
    bool install(const QString& file, XQInstaller::Drive drive);
    bool remove(uint uid);
    QMap<QString, uint> applications() const;

public:
    XQInstaller::Error error();
    
protected:  
    void DoCancel();
    void RunL();

private:
    XQInstaller *q;
    mutable int iError;
    
    SwiUI::RSWInstSilentLauncher iLauncher;
    SwiUI::TInstallOptions iOptions;
    SwiUI::TInstallOptionsPckg iOptionsPckg;  
    
    SwiUI::TUninstallOptions iUninstallOptions;
    SwiUI::TUninstallOptionsPckg iUninstallOptionsPckg;
    XQInstallerPrivate::State iState;
    TFileName iFileName;
    bool iLauncherConnected;
};

#endif /*XQINSTALLER_P_H*/

// End of file

xqinstaller_h.cpp

#include "xqinstaller.h"
#include "xqinstaller_p.h"
#include <f32file.h>
#include <apgcli.h>

XQInstallerPrivate::XQInstallerPrivate(XQInstaller *installer) 
    : CActive(EPriorityNormal), q(installer), iOptionsPckg(iOptions), 
      iUninstallOptionsPckg(iUninstallOptions), iLauncherConnected(false)
{
    CActiveScheduler::Add(this);  
}

XQInstallerPrivate::~XQInstallerPrivate()
{
    Cancel();
    if (iLauncherConnected) {
        iLauncher.Close();
    }
}

bool XQInstallerPrivate::install(const QString& file, XQInstaller::Drive drive)
{
    int asciiValue = 10;  // = 'A'
    TRAP(iError,
        if (!iLauncherConnected) {
            User::LeaveIfError(iLauncher.Connect());
            iLauncherConnected = true;
        }
        if (IsActive()) {
            User::Leave(KErrInUse);
        }
        
        iState = XQInstallerPrivate::EInstall;
        iOptions.iUpgrade = SwiUI::EPolicyAllowed;
        iOptions.iOCSP = SwiUI::EPolicyNotAllowed;
        iOptions.iDrive = TChar(asciiValue+drive);
        iOptions.iUntrusted = SwiUI::EPolicyAllowed; 
        iOptions.iCapabilities = SwiUI::EPolicyAllowed;  
        iOptions.iOptionalItems = SwiUI::EPolicyAllowed;  
        iOptions.iOverwrite = SwiUI::EPolicyAllowed; 
        TPtrC16 fileName(reinterpret_cast<const TUint16*>(file.utf16()));
        iFileName = fileName;
        iLauncher.SilentInstall(iStatus, iFileName, iOptionsPckg);
        SetActive();
    )
    return (iError == KErrNone);
}

bool XQInstallerPrivate::remove(uint uid)
{
    TRAP(iError,
        if (!iLauncherConnected) {
            User::LeaveIfError(iLauncher.Connect());
            iLauncherConnected = true;
        }
        if (IsActive()) {
            User::Leave(KErrInUse);
        }

        iState = XQInstallerPrivate::ERemove;
    
        iLauncher.SilentUninstall(iStatus,TUid::Uid(uid),
            iUninstallOptionsPckg, SwiUI::KSisxMimeType);
        SetActive();
    )
    return (iError == KErrNone);
}

QMap<QString, uint> XQInstallerPrivate::applications() const
{
    RApaLsSession lsSession;
    QMap<QString, uint> applications; 
      
    // Connect to application architecture server
    TRAP(iError,
        User::LeaveIfError(lsSession.Connect());
        CleanupClosePushL(lsSession);
        
        TApaAppInfo appInfo;
        lsSession.GetAllApps();  
        
        while (lsSession.GetNextApp(appInfo) == KErrNone) {
            TApaAppCapabilityBuf capability;
            User::LeaveIfError(lsSession.GetAppCapability(capability,
                appInfo.iUid));
            if (appInfo.iCaption.Length() > 0 && !capability().iAppIsHidden) {
                QString fullName = QString::fromUtf16(
                    appInfo.iCaption.Ptr(), appInfo.iCaption.Length());
                applications.insert(fullName, (TUint)appInfo.iUid.iUid);
            }
        }
        CleanupStack::PopAndDestroy(&lsSession);
    )
      
    return applications; 
}

void XQInstallerPrivate::DoCancel()
{
    if (iState == XQInstallerPrivate::EInstall) {
        iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentInstall);
    } else if (iState == XQInstallerPrivate::ERemove) {
        iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentUninstall);
    }
}
 
void XQInstallerPrivate::RunL()
{
    if (iStatus.Int() == KErrNone) {
        if (iState == XQInstallerPrivate::EInstall) {
            emit q->applicationInstalled();
        } else if (iState == XQInstallerPrivate::ERemove) {
            emit q->applicationRemoved();
        }
    } else {
        iError = iStatus.Int();
        emit q->error(error());
    }
}

XQInstaller::Error XQInstallerPrivate::error()
{
    switch (iError) {
    case KErrNone:
        return XQInstaller::NoError;
    case SwiUI::KSWInstErrInsufficientMemory:
    case KErrNoMemory:
        return XQInstaller::OutOfMemoryError;
    case SwiUI::KSWInstErrFileInUse:
    case KErrInUse:
        return XQInstaller::AlreadyInUseError;
    case SwiUI::KSWInstErrUserCancel:
        return XQInstaller::UserCancelError;  
    case SwiUI::KSWInstErrPackageNotSupported:
        return XQInstaller::PackageNotSupportedError; 
    case SwiUI::KSWInstErrSecurityFailure:
        return XQInstaller::SecurityFailureError; 
    case SwiUI::KSWInstErrMissingDependency:
        return XQInstaller::MissingDependencyError; 
    case SwiUI::KSWInstErrNoRights:
        return XQInstaller::NoRightsError;
    case SwiUI::KSWInstErrBusy:
        return XQInstaller::BusyError;
    case SwiUI::KSWInstErrAccessDenied:
        return XQInstaller::AccessDeniedError;
    case SwiUI::KSWInstUpgradeError:
        return XQInstaller::UpgradeError;
    case SwiUI::KSWInstErrGeneralError:
    default:
        return XQInstaller::UnknownError;
    }    
}
 
// End of file

そしてQIconを取得するために::

必要な聞き手:

#include <fbs.h> //CFbsBitmap
#include <aknsskininstance.h> //MAknsSkinInstance 
#include <aknsutils.h> //AknsUtils

必要なライブラリ:

LIBRARY   fbscli.lib ///CFbsBitmap
LIBRARY   aknskins.lib aknskinsrv.lib aknswallpaperutils.lib  //MAknsSkinInstance ,AknsUtils

ソースコード:

CGulIcon* CMyClass::GetApplicationIconL(const TUid& aAppUID)
{
    CFbsBitmap* AppIcon(NULL);
    CFbsBitmap* AppIconMsk(NULL);
 
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
 
    AknsUtils::CreateAppIconLC(skin,aAppUID,  EAknsAppIconTypeContext,AppIcon,AppIconMsk);
    CleanupStack::Pop(2);
 
    return CGulIcon::NewL(AppIcon,AppIconMsk);
}
于 2012-05-27T16:57:57.853 に答える
-1

さて、アイコンについてはこれを見てください:CGullIconには、ビットマップを返す関数、CFbsBitmapがあります。http://qt-project.org/doc/qt-4.8/qpixmap.html#fromSymbianCFbsBitmap次に、新しいQIcon(QPixmap)を作成します(QPixmap =変換したアイコン) 。したがって、最初にCFbsBitmapに渡し、次にQPixmapでfromSymibnaCFbsBitmap()を使用する可能性があります。

CApaMaskedBitmapは、私が間違っていなければCFbsBitmapのサブクラスなので、同じように機能するはずです。

また、アプリケーションとそのUIDを取得するには、次を参照してください。http ://www.developer.nokia.com/Community/Wiki/Get_list_of_installed_applications_and_its_UID_in_Qt

于 2012-05-27T16:24:37.307 に答える