emailuis/nmailui/src/nmuriserviceinterface.cpp
author hgs
Tue, 19 Oct 2010 12:30:59 +0300
changeset 79 2508e95245f2
parent 74 6c59112cfd31
permissions -rw-r--r--
201041_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: NMail Application Launcher interface used for interfacing between
hgs
parents:
diff changeset
    15
*              QT highway and other applications
hgs
parents:
diff changeset
    16
*
hgs
parents:
diff changeset
    17
*/
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
//  INCLUDES
hgs
parents:
diff changeset
    20
#include "nmuiheaders.h"
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
/*!
hgs
parents:
diff changeset
    23
    \class NmUriServiceInterface
hgs
parents:
diff changeset
    24
    \brief NMail application service interface which provides an email sending
hgs
parents:
diff changeset
    25
           interface for other application using the Qt Highway.
hgs
parents:
diff changeset
    26
*/
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
/*!
hgs
parents:
diff changeset
    29
    Class constructor.
hgs
parents:
diff changeset
    30
*/
hgs
parents:
diff changeset
    31
NmUriServiceInterface::NmUriServiceInterface(QObject *parent,
hgs
parents:
diff changeset
    32
                                               NmUiEngine &uiEngine,
hgs
parents:
diff changeset
    33
                                               NmApplication *application)
hgs
parents:
diff changeset
    34
    : XQServiceProvider(emailServiceName+"."+XQI_URI_VIEW, parent),
hgs
parents:
diff changeset
    35
      mApplication(application),
hgs
parents:
diff changeset
    36
      mUiEngine(uiEngine),
hgs
parents:
diff changeset
    37
      mAsyncReqId(0),
hgs
parents:
diff changeset
    38
      mStartParam(NULL),
hgs
parents:
diff changeset
    39
      mSelectionDialog(NULL),
hgs
parents:
diff changeset
    40
      mCurrentView(NULL)
hgs
parents:
diff changeset
    41
{
hgs
parents:
diff changeset
    42
    publishAll();
hgs
parents:
diff changeset
    43
}
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
/*!
hgs
parents:
diff changeset
    47
    Class desctructor.
hgs
parents:
diff changeset
    48
*/
hgs
parents:
diff changeset
    49
NmUriServiceInterface::~NmUriServiceInterface()
hgs
parents:
diff changeset
    50
{
hgs
parents:
diff changeset
    51
    NM_FUNCTION;
hgs
parents:
diff changeset
    52
    
hgs
parents:
diff changeset
    53
    delete mStartParam;
hgs
parents:
diff changeset
    54
    delete mSelectionDialog;
hgs
parents:
diff changeset
    55
}
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
/*!
hgs
parents:
diff changeset
    59
    Queries the user for a mailbox to use.
hgs
parents:
diff changeset
    60
    \param mailboxId Where the ID of the selected mailbox is set.
hgs
parents:
diff changeset
    61
    \return True if a mailbox was selected, false otherwise.
hgs
parents:
diff changeset
    62
*/
hgs
parents:
diff changeset
    63
void NmUriServiceInterface::selectionDialogClosed(NmId &mailboxId)
hgs
parents:
diff changeset
    64
{
hgs
parents:
diff changeset
    65
    NM_FUNCTION;
hgs
parents:
diff changeset
    66
    
hgs
parents:
diff changeset
    67
    if (mailboxId.id()) { // mailbox selected
hgs
parents:
diff changeset
    68
        launchEditorView(mailboxId);
hgs
parents:
diff changeset
    69
    }
hgs
parents:
diff changeset
    70
    else {
hgs
parents:
diff changeset
    71
        cancelService();
hgs
parents:
diff changeset
    72
    }
hgs
parents:
diff changeset
    73
}
hgs
parents:
diff changeset
    74
hgs
parents:
diff changeset
    75
hgs
parents:
diff changeset
    76
/*!
hgs
parents:
diff changeset
    77
    Used from external applications to handle mailto: uri's.
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
    \param data <mailto:> uri
hgs
parents:
diff changeset
    80
*/
hgs
parents:
diff changeset
    81
bool NmUriServiceInterface::view(const QString& uri)
hgs
parents:
diff changeset
    82
{
hgs
parents:
diff changeset
    83
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
    84
      
hgs
parents: 43
diff changeset
    85
    HbMainWindow *mainWindow(NULL);
hgs
parents: 43
diff changeset
    86
    if (mApplication) {
hgs
parents: 43
diff changeset
    87
        // Make sure that nmail stays background if user presses back in editorview
hgs
parents: 43
diff changeset
    88
        mApplication->updateVisibilityState();
hgs
parents: 43
diff changeset
    89
        
hgs
parents: 43
diff changeset
    90
        mainWindow = mApplication->mainWindow();
hgs
parents: 43
diff changeset
    91
        if (mainWindow) {
hgs
parents: 43
diff changeset
    92
            mCurrentView = mainWindow->currentView();  
hgs
parents: 43
diff changeset
    93
        } 
hgs
parents: 43
diff changeset
    94
    }
43
hgs
parents:
diff changeset
    95
hgs
parents:
diff changeset
    96
    // Hide the current view.
hgs
parents:
diff changeset
    97
    if (mCurrentView) {
hgs
parents:
diff changeset
    98
        mCurrentView->hide();
hgs
parents:
diff changeset
    99
    }
hgs
parents:
diff changeset
   100
    
hgs
parents:
diff changeset
   101
    // Check the given data.
74
hgs
parents: 68
diff changeset
   102
    NmUriParser uriParser;
hgs
parents: 68
diff changeset
   103
    bool validData = uriParser.extractData(uri);
hgs
parents: 68
diff changeset
   104
    
43
hgs
parents:
diff changeset
   105
     
hgs
parents:
diff changeset
   106
    NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel();
hgs
parents:
diff changeset
   107
    const int count = mailboxListModel.rowCount();
hgs
parents:
diff changeset
   108
    NmId mailboxId(0);
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
    mAsyncReqId = setCurrentRequestAsync();
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
    if (!validData) {
hgs
parents:
diff changeset
   113
        // Failed to extract the data!
hgs
parents:
diff changeset
   114
        NM_ERROR(1,"NmUriServiceInterface::view(): failed to process the given data");
hgs
parents:
diff changeset
   115
        cancelService();
hgs
parents:
diff changeset
   116
    }
hgs
parents:
diff changeset
   117
    else if (count == 0) {
hgs
parents:
diff changeset
   118
        HbDeviceMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"),
hgs
parents:
diff changeset
   119
                          HbMessageBox::MessageTypeInformation);
hgs
parents:
diff changeset
   120
        note.setTimeout(HbMessageBox::NoTimeout);
hgs
parents:
diff changeset
   121
        note.show();
hgs
parents:
diff changeset
   122
        cancelService();
hgs
parents:
diff changeset
   123
    }
hgs
parents:
diff changeset
   124
    else { // count > 0
47
hgs
parents: 43
diff changeset
   125
        if (mainWindow) {
74
hgs
parents: 68
diff changeset
   126
            mainWindow->show();
47
hgs
parents: 43
diff changeset
   127
        }
74
hgs
parents: 68
diff changeset
   128
        
hgs
parents: 68
diff changeset
   129
        // The ownership of these is passed to NmApplication in launchEditorView()
hgs
parents: 68
diff changeset
   130
        QList<NmAddress*> *toAddresses = NmUtilities::qstringListToNmAddressList(uriParser.toAddresses());
hgs
parents: 68
diff changeset
   131
        QList<NmAddress*> *ccAddresses = NmUtilities::qstringListToNmAddressList(uriParser.ccAddresses());
hgs
parents: 68
diff changeset
   132
        QList<NmAddress*> *bccAddresses = NmUtilities::qstringListToNmAddressList(uriParser.bccAddresses());
hgs
parents: 68
diff changeset
   133
        
hgs
parents: 68
diff changeset
   134
        QString* subject = new QString(uriParser.subject());
hgs
parents: 68
diff changeset
   135
        QString* bodyText = new QString(uriParser.bodyText());
hgs
parents: 68
diff changeset
   136
       
43
hgs
parents:
diff changeset
   137
    	mStartParam = new NmUiStartParam(
hgs
parents:
diff changeset
   138
        	NmUiViewMessageEditor,
hgs
parents:
diff changeset
   139
	        0, // account id
hgs
parents:
diff changeset
   140
	        0, // folder id
hgs
parents:
diff changeset
   141
    	    0, // message id
hgs
parents:
diff changeset
   142
    	    NmUiEditorMailto, // editor start mode
74
hgs
parents: 68
diff changeset
   143
    	    toAddresses,
68
hgs
parents: 62
diff changeset
   144
    	    NULL, // attachment list
43
hgs
parents:
diff changeset
   145
        	true, // start as service
74
hgs
parents: 68
diff changeset
   146
        	subject, // message subject
hgs
parents: 68
diff changeset
   147
            ccAddresses, // list containing cc recipient addresses
hgs
parents: 68
diff changeset
   148
            bccAddresses, // list containing bcc recipient addresses
hgs
parents: 68
diff changeset
   149
            bodyText // body text
43
hgs
parents:
diff changeset
   150
	    );
74
hgs
parents: 68
diff changeset
   151
	    
43
hgs
parents:
diff changeset
   152
        if (count == 1) {
hgs
parents:
diff changeset
   153
            // A single mailbox exists.
hgs
parents:
diff changeset
   154
            QModelIndex modelIndex = mailboxListModel.index(0, 0);
hgs
parents:
diff changeset
   155
            QVariant mailbox(mailboxListModel.data(modelIndex));
hgs
parents:
diff changeset
   156
            NmMailboxMetaData *mailboxMetaData = mailbox.value<NmMailboxMetaData*>();
hgs
parents:
diff changeset
   157
            mailboxId = mailboxMetaData->id();
hgs
parents:
diff changeset
   158
        	launchEditorView(mailboxId);
hgs
parents:
diff changeset
   159
        }
hgs
parents:
diff changeset
   160
        else { // count > 1
hgs
parents:
diff changeset
   161
            if (!mSelectionDialog) {
hgs
parents:
diff changeset
   162
                mSelectionDialog =
hgs
parents:
diff changeset
   163
                    new NmMailboxSelectionDialog(mUiEngine.mailboxListModel());
hgs
parents:
diff changeset
   164
            }
62
hgs
parents: 47
diff changeset
   165
            
hgs
parents: 47
diff changeset
   166
            if (!XQServiceUtil::isEmbedded()) {
hgs
parents: 47
diff changeset
   167
                XQServiceUtil::toBackground(false);
hgs
parents: 47
diff changeset
   168
            }
hgs
parents: 47
diff changeset
   169
            
43
hgs
parents:
diff changeset
   170
            connect(mSelectionDialog,SIGNAL(selectionDialogClosed(NmId&)),
hgs
parents:
diff changeset
   171
                this,SLOT(selectionDialogClosed(NmId&)));
hgs
parents:
diff changeset
   172
            mSelectionDialog->open();
hgs
parents:
diff changeset
   173
hgs
parents:
diff changeset
   174
            // launch the editor when the dialog is closed
hgs
parents:
diff changeset
   175
        }
hgs
parents:
diff changeset
   176
    }
hgs
parents:
diff changeset
   177
    return true;
hgs
parents:
diff changeset
   178
}
hgs
parents:
diff changeset
   179
hgs
parents:
diff changeset
   180
/*!
hgs
parents:
diff changeset
   181
    Called when mailbox id is known and editor can be opened
hgs
parents:
diff changeset
   182
    \param mailboxId mailbox using in editor
hgs
parents:
diff changeset
   183
 */
hgs
parents:
diff changeset
   184
void NmUriServiceInterface::launchEditorView(NmId mailboxId)
hgs
parents:
diff changeset
   185
{
hgs
parents:
diff changeset
   186
    NM_FUNCTION;
hgs
parents:
diff changeset
   187
    NM_COMMENT(QString("NmUriServiceInterface::launchEditorView(): mailboxId=%1").arg(mailboxId.id()));
hgs
parents:
diff changeset
   188
    
hgs
parents:
diff changeset
   189
    // Make the previous view visible again.
hgs
parents:
diff changeset
   190
    if (mCurrentView) {
hgs
parents:
diff changeset
   191
        mCurrentView->show();
hgs
parents:
diff changeset
   192
        mCurrentView = NULL;
hgs
parents:
diff changeset
   193
    }
hgs
parents:
diff changeset
   194
hgs
parents:
diff changeset
   195
    if (mStartParam) {
62
hgs
parents: 47
diff changeset
   196
        // Make sure the NMail application is in the foreground
hgs
parents: 47
diff changeset
   197
        if (!XQServiceUtil::isEmbedded()) {
hgs
parents: 47
diff changeset
   198
            XQServiceUtil::toBackground(false);    
hgs
parents: 47
diff changeset
   199
        }
hgs
parents: 47
diff changeset
   200
        
43
hgs
parents:
diff changeset
   201
        mStartParam->setMailboxId(mailboxId);
hgs
parents:
diff changeset
   202
        mApplication->enterNmUiView(mStartParam);
hgs
parents:
diff changeset
   203
        mStartParam = NULL; // ownership passed
hgs
parents:
diff changeset
   204
    }
hgs
parents:
diff changeset
   205
    completeRequest(mAsyncReqId, 1);
hgs
parents:
diff changeset
   206
    mAsyncReqId = 0;
hgs
parents:
diff changeset
   207
}
hgs
parents:
diff changeset
   208
hgs
parents:
diff changeset
   209
void NmUriServiceInterface::cancelService()
hgs
parents:
diff changeset
   210
{
hgs
parents:
diff changeset
   211
    NM_FUNCTION;
hgs
parents:
diff changeset
   212
    
hgs
parents:
diff changeset
   213
    delete mStartParam;
hgs
parents:
diff changeset
   214
    mStartParam = NULL;
hgs
parents:
diff changeset
   215
hgs
parents:
diff changeset
   216
    // If the service was started as embedded, do not hide the app.
hgs
parents:
diff changeset
   217
    if (!XQServiceUtil::isEmbedded()) {
hgs
parents:
diff changeset
   218
        XQServiceUtil::toBackground(true);
hgs
parents:
diff changeset
   219
    }
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
    completeRequest(mAsyncReqId, 0);
hgs
parents:
diff changeset
   222
    mAsyncReqId = 0;
hgs
parents:
diff changeset
   223
hgs
parents:
diff changeset
   224
    // If started as service, the application must be closed now.
hgs
parents:
diff changeset
   225
    if (XQServiceUtil::isService()) {
hgs
parents:
diff changeset
   226
        connect(this, SIGNAL(returnValueDelivered()),
hgs
parents:
diff changeset
   227
            mApplication, SLOT(delayedExitApplication()));
hgs
parents:
diff changeset
   228
    }
hgs
parents:
diff changeset
   229
    else {
hgs
parents:
diff changeset
   230
        // Make the previous view visible again
hgs
parents:
diff changeset
   231
        if (mCurrentView) {
hgs
parents:
diff changeset
   232
            mCurrentView->show();
hgs
parents:
diff changeset
   233
            mCurrentView = NULL;
hgs
parents:
diff changeset
   234
        }
hgs
parents:
diff changeset
   235
    }
hgs
parents:
diff changeset
   236
}
hgs
parents:
diff changeset
   237
hgs
parents:
diff changeset
   238
// End of file.