qthighway/examples/mimetestapp2/src/mimetestapp.cpp
branchRCL_3
changeset 22 5d007b20cfd0
equal deleted inserted replaced
21:885c2596c964 22:5d007b20cfd0
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 *
       
    20 */
       
    21 
       
    22 #include <QtGlobal>
       
    23 #include <QApplication>
       
    24 #include <QKeyEvent>
       
    25 #include <QLabel>
       
    26 #include <QStackedWidget>
       
    27 #include <QImageReader>
       
    28 #include <QDebug>
       
    29 #include <QTimer>
       
    30 #include <QPushButton>
       
    31 #include <QList>
       
    32 #include <QLineEdit>
       
    33 #include <QString>
       
    34 #include <QCheckBox>
       
    35 #include <QAction>
       
    36 #include <QListView>
       
    37 #include <QUrl>
       
    38 #include <math.h>
       
    39 #include "xqservicelog.h"
       
    40 
       
    41 #include "mimetestapp.h"
       
    42 
       
    43 MimeTestApp::MimeTestApp(QWidget *parent, Qt::WFlags f)
       
    44     : QWidget(parent, f), mFileService(0), mLabel(0), mVl(0)
       
    45 {
       
    46     /* Adjust the palette */
       
    47 #if defined(Q_WS_S60)
       
    48     QPalette p = qApp->palette();
       
    49     QColor color(192,192,192);
       
    50     QColor bg(201,250,250);
       
    51     p.setColor(QPalette::Highlight, color.lighter(200));
       
    52     p.setColor(QPalette::Text, Qt::black);
       
    53     p.setColor(QPalette::Base, bg);
       
    54     p.setColor(QPalette::WindowText, Qt::black);
       
    55     p.setColor(QPalette::Window, bg);
       
    56     p.setColor(QPalette::ButtonText, Qt::black);
       
    57     p.setColor(QPalette::Button, color.lighter(150));
       
    58     p.setColor(QPalette::Link, QColor(240,40,40));
       
    59 
       
    60     qApp->setPalette(p);
       
    61 #endif
       
    62 
       
    63     QPushButton *quitButton = new QPushButton(tr("quit"));
       
    64     connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
       
    65 
       
    66     mVl = new QVBoxLayout;
       
    67     mVl->setMargin(0);
       
    68     mVl->setSpacing(0);
       
    69 
       
    70     mLabel = new QLabel("");
       
    71     mVl->addWidget(mLabel);
       
    72     
       
    73     QStringList args = QApplication::arguments();
       
    74     QString argsTxt;
       
    75     foreach (QString arg, args)
       
    76     {
       
    77         argsTxt += arg + "\n";
       
    78     }
       
    79 
       
    80     QLabel *cmdArgsLabel = new QLabel(argsTxt);
       
    81     mVl->addWidget(cmdArgsLabel);
       
    82     
       
    83     mVl->addWidget(quitButton);
       
    84     setLayout(mVl);
       
    85 
       
    86 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
       
    87     setFixedSize(QSize(360,640)); // nHD
       
    88 #elif defined(Q_WS_S60)
       
    89     showMaximized();
       
    90     showFullScreen();
       
    91 #endif
       
    92 
       
    93     // Activate service
       
    94     mFileService = new FileService(this);
       
    95     
       
    96 }
       
    97 
       
    98 MimeTestApp::~MimeTestApp()
       
    99 {
       
   100     delete mFileService;
       
   101 }
       
   102 
       
   103 void MimeTestApp::setLabel(QString label)
       
   104 {
       
   105     XQSERVICE_DEBUG_PRINT("MimeTestApp2::setLabel");
       
   106     mLabel->setText(label);
       
   107 }
       
   108 
       
   109 
       
   110 // ----------FileService---------------
       
   111 
       
   112 FileService::FileService(MimeTestApp* parent)
       
   113 : XQServiceProvider(QLatin1String("mimetestapp2.com.nokia.symbian.IFileView"),parent),
       
   114   mMimeTestApp(parent)
       
   115 
       
   116 {
       
   117     XQSERVICE_DEBUG_PRINT("MimeTestApp2::FileService (mimetestapp2)");
       
   118     publishAll();
       
   119 }
       
   120 
       
   121 FileService::~FileService()
       
   122 {
       
   123     XQSERVICE_DEBUG_PRINT("MimeTestApp2::~FileService  (mimetestapp2)");
       
   124 }
       
   125 
       
   126 bool FileService::view(QString file)
       
   127 {
       
   128     XQSERVICE_DEBUG_PRINT("MimeTestApp2::view(QString) (mimetestapp2) %s",
       
   129                          qPrintable(file));
       
   130 
       
   131     QString label = "IFileView:" + QString ("File=%1\n").arg(file);
       
   132     mMimeTestApp->setLabel(label);
       
   133     
       
   134     return true;
       
   135 }
       
   136 
       
   137 
       
   138 bool FileService::view(XQSharableFile sf)
       
   139 {
       
   140     XQSERVICE_DEBUG_PRINT("MimeTestApp2::view(XQSharebleFile) (mimetestapp2)");
       
   141     QString label = "IFileView:" + QString ("File=%1\n").arg(sf.fileName());
       
   142 
       
   143     RFile file;
       
   144     bool ok = sf.getHandle( file );
       
   145     if (ok)
       
   146     {
       
   147         HBufC8* data = HBufC8::NewL(100);
       
   148         TPtr8 ptr = data->Des();
       
   149         TInt err  = file.Read( ptr );
       
   150         QString text = QString::fromUtf8((const char *)(data->Ptr()), data->Length());
       
   151         XQSERVICE_DEBUG_PRINT("MimeTestApp2::file read,%d,%s", err, qPrintable(text));
       
   152         sf.close();
       
   153         delete data;
       
   154     }
       
   155 
       
   156     mMimeTestApp->setLabel(label);
       
   157     
       
   158     return true;
       
   159 }
       
   160 
       
   161