phonebookui/pbkcommonui/src/cntgroupmemberview_p.cpp
author hgs
Fri, 03 Sep 2010 14:32:33 +0300
changeset 66 554fe4dbbb59
parent 61 d30183af6ca6
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 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:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "cntgroupmemberview_p.h"
hgs
parents:
diff changeset
    19
#include "cntfetchcontactpopup.h"
hgs
parents:
diff changeset
    20
#include "cntcontactcardheadingitem.h"
hgs
parents:
diff changeset
    21
#include "cntglobal.h"
hgs
parents:
diff changeset
    22
#include "cntimagelabel.h"
hgs
parents:
diff changeset
    23
#include "cntimageutility.h"
61
hgs
parents: 54
diff changeset
    24
#include "cntthumbnailmanager.h"
54
hgs
parents:
diff changeset
    25
#include <hbnotificationdialog.h>
hgs
parents:
diff changeset
    26
#include <hbmessagebox.h>
hgs
parents:
diff changeset
    27
#include <hbmenu.h>
hgs
parents:
diff changeset
    28
#include <hblistview.h>
hgs
parents:
diff changeset
    29
#include <hblistviewitem.h>
hgs
parents:
diff changeset
    30
#include <hbframebackground.h>
hgs
parents:
diff changeset
    31
#include <hbindexfeedback.h>
hgs
parents:
diff changeset
    32
#include <hbscrollbar.h>
hgs
parents:
diff changeset
    33
#include <hbview.h>
hgs
parents:
diff changeset
    34
#include <hbaction.h>
hgs
parents:
diff changeset
    35
#include <hblabel.h>
hgs
parents:
diff changeset
    36
#include <hbparameterlengthlimiter.h>
hgs
parents:
diff changeset
    37
#include <cntlistmodel.h>
hgs
parents:
diff changeset
    38
#include <hbmainwindow.h>
hgs
parents:
diff changeset
    39
#include <xqservicerequest.h>
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
#include "cntdocumentloader.h"
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
const char *CNT_GROUPMEMBERVIEW_XML = ":/xml/contacts_groupmembers.docml";
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
/*!
hgs
parents:
diff changeset
    46
\class CntGroupMemberViewPrivate
hgs
parents:
diff changeset
    47
\brief
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
This is the group members view class that shows list of contacts for a user group. View contains a listview that shows actual contacts that
hgs
parents:
diff changeset
    50
have been added to a particular group. There is also toolbar and menu for navigating between different views. Instance of this class is
hgs
parents:
diff changeset
    51
created by our viewmanager but view itself is owned by the mainwindow which will also delete it in the end.
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
*/
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
/*!
hgs
parents:
diff changeset
    56
Constructor, initialize member variables.
hgs
parents:
diff changeset
    57
\a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
*/
hgs
parents:
diff changeset
    60
CntGroupMemberViewPrivate::CntGroupMemberViewPrivate() :
hgs
parents:
diff changeset
    61
    mGroupContact(NULL),
hgs
parents:
diff changeset
    62
    mViewManager(NULL),
hgs
parents:
diff changeset
    63
    mHeadingItem(NULL),
hgs
parents:
diff changeset
    64
    mModel(NULL),
hgs
parents:
diff changeset
    65
    mImageLabel(NULL), 
hgs
parents:
diff changeset
    66
    mListView(NULL),
hgs
parents:
diff changeset
    67
    mAvatar(NULL)
hgs
parents:
diff changeset
    68
{
hgs
parents:
diff changeset
    69
    mDocument = new CntDocumentLoader;
hgs
parents:
diff changeset
    70
    
hgs
parents:
diff changeset
    71
    bool ok;
hgs
parents:
diff changeset
    72
    mDocument->load( CNT_GROUPMEMBERVIEW_XML, &ok );
hgs
parents:
diff changeset
    73
    if ( !ok ){
hgs
parents:
diff changeset
    74
        qFatal( "Unable to load %S", CNT_GROUPMEMBERVIEW_XML );
hgs
parents:
diff changeset
    75
    }
hgs
parents:
diff changeset
    76
hgs
parents:
diff changeset
    77
    mView = static_cast<HbView*>( mDocument->findWidget("view") );
hgs
parents:
diff changeset
    78
    
hgs
parents:
diff changeset
    79
    //back button
hgs
parents:
diff changeset
    80
    mSoftkey = new HbAction(Hb::BackNaviAction, mView);
hgs
parents:
diff changeset
    81
    connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
hgs
parents:
diff changeset
    82
    
hgs
parents:
diff changeset
    83
    mImageLabel = static_cast<CntImageLabel*>(mDocument->findWidget("editViewImage"));
hgs
parents:
diff changeset
    84
    connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) );
hgs
parents:
diff changeset
    85
    connect( mImageLabel, SIGNAL(iconLongPressed(const QPointF&)), this, SLOT(drawImageMenu(const QPointF&)) );
hgs
parents:
diff changeset
    86
    
hgs
parents:
diff changeset
    87
    mListView = static_cast<HbListView*>( mDocument->findWidget("listView") );
hgs
parents:
diff changeset
    88
    connect(mListView, SIGNAL(longPressed(HbAbstractViewItem*,QPointF)), this,
hgs
parents:
diff changeset
    89
        SLOT(showContextMenu(HbAbstractViewItem*,QPointF)));
hgs
parents:
diff changeset
    90
    connect(mListView, SIGNAL(activated (const QModelIndex&)), this,
hgs
parents:
diff changeset
    91
        SLOT(showContactView(const QModelIndex&)));
hgs
parents:
diff changeset
    92
    
hgs
parents:
diff changeset
    93
    mHeadingItem = static_cast<CntContactCardHeadingItem*>( mDocument->findWidget("editViewHeading") );
hgs
parents:
diff changeset
    94
    connect(mHeadingItem, SIGNAL(passShortPressed(const QPointF&)), this, SLOT(openImageEditor()) );
hgs
parents:
diff changeset
    95
    connect(mHeadingItem, SIGNAL(passLongPressed(const QPointF&)), this, SLOT(drawImageMenu(const QPointF&)));
hgs
parents:
diff changeset
    96
hgs
parents:
diff changeset
    97
    // menu actions
hgs
parents:
diff changeset
    98
    mEditGroupAction = static_cast<HbAction*>( mDocument->findObject("cnt:editgroupdetails"));
hgs
parents:
diff changeset
    99
    connect(mEditGroupAction, SIGNAL(triggered()), this, SLOT(editGroup()));
hgs
parents:
diff changeset
   100
    
hgs
parents:
diff changeset
   101
    // toolbar actions
hgs
parents:
diff changeset
   102
    mManageAction = static_cast<HbAction*>( mDocument->findObject("cnt:managemembers"));
hgs
parents:
diff changeset
   103
    connect(mManageAction, SIGNAL(triggered()), this, SLOT(manageMembers()));
hgs
parents:
diff changeset
   104
    mDeleteAction = static_cast<HbAction*>( mDocument->findObject("cnt:deletegroup"));
hgs
parents:
diff changeset
   105
    connect(mDeleteAction, SIGNAL(triggered()), this, SLOT(deleteGroup()));
hgs
parents:
diff changeset
   106
    mShowActionsAction = static_cast<HbAction*>( mDocument->findObject("cnt:groupactions"));
hgs
parents:
diff changeset
   107
    connect(mShowActionsAction, SIGNAL(triggered()), this, SLOT(openGroupActions()));
hgs
parents:
diff changeset
   108
}
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
/*!
hgs
parents:
diff changeset
   111
Destructor
hgs
parents:
diff changeset
   112
*/
hgs
parents:
diff changeset
   113
CntGroupMemberViewPrivate::~CntGroupMemberViewPrivate()
hgs
parents:
diff changeset
   114
{
hgs
parents:
diff changeset
   115
    mView->deleteLater();
hgs
parents:
diff changeset
   116
    
hgs
parents:
diff changeset
   117
    delete mGroupContact;
hgs
parents:
diff changeset
   118
    mGroupContact = NULL;
hgs
parents:
diff changeset
   119
    
hgs
parents:
diff changeset
   120
    delete mModel;
hgs
parents:
diff changeset
   121
    mModel = NULL;
hgs
parents:
diff changeset
   122
    
hgs
parents:
diff changeset
   123
    delete mAvatar;
hgs
parents:
diff changeset
   124
    mAvatar = NULL;
hgs
parents:
diff changeset
   125
}
hgs
parents:
diff changeset
   126
hgs
parents:
diff changeset
   127
void CntGroupMemberViewPrivate::setOrientation(Qt::Orientation orientation)
hgs
parents:
diff changeset
   128
{
hgs
parents:
diff changeset
   129
    if (orientation == Qt::Vertical) 
hgs
parents:
diff changeset
   130
    {
hgs
parents:
diff changeset
   131
        // reading "portrait" section
hgs
parents:
diff changeset
   132
        mDocument->load( CNT_GROUPMEMBERVIEW_XML, "portrait" );
hgs
parents:
diff changeset
   133
    } 
hgs
parents:
diff changeset
   134
    else 
hgs
parents:
diff changeset
   135
    {
hgs
parents:
diff changeset
   136
        // reading "landscape" section
hgs
parents:
diff changeset
   137
        mDocument->load( CNT_GROUPMEMBERVIEW_XML, "landscape" );
hgs
parents:
diff changeset
   138
    }
hgs
parents:
diff changeset
   139
}
hgs
parents:
diff changeset
   140
61
hgs
parents: 54
diff changeset
   141
void CntGroupMemberViewPrivate::activate( const CntViewParameters aArgs )
54
hgs
parents:
diff changeset
   142
{
hgs
parents:
diff changeset
   143
    mArgs = aArgs;
61
hgs
parents: 54
diff changeset
   144
    mViewManager = &mEngine->viewManager();
hgs
parents: 54
diff changeset
   145
    mThumbnailManager = &mEngine->thumbnailManager();
hgs
parents: 54
diff changeset
   146
hgs
parents: 54
diff changeset
   147
    connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
hgs
parents: 54
diff changeset
   148
            this, SLOT(thumbnailReady(QPixmap, void*, int, int)));
hgs
parents: 54
diff changeset
   149
        
54
hgs
parents:
diff changeset
   150
    if (mView->navigationAction() != mSoftkey)
hgs
parents:
diff changeset
   151
        {
hgs
parents:
diff changeset
   152
        mView->setNavigationAction(mSoftkey);   
hgs
parents:
diff changeset
   153
        }
hgs
parents:
diff changeset
   154
        
hgs
parents:
diff changeset
   155
    QVariant contact = mArgs.value( ESelectedGroupContact );
hgs
parents:
diff changeset
   156
    mGroupContact = new QContact( contact.value<QContact>() );
hgs
parents:
diff changeset
   157
    
hgs
parents:
diff changeset
   158
    HbMainWindow* window = mView->mainWindow();
hgs
parents:
diff changeset
   159
    if ( window )
hgs
parents:
diff changeset
   160
    {
hgs
parents:
diff changeset
   161
        connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
hgs
parents:
diff changeset
   162
        setOrientation(window->orientation());
hgs
parents:
diff changeset
   163
    }
hgs
parents:
diff changeset
   164
    
hgs
parents:
diff changeset
   165
    mHeadingItem->setGroupDetails(mGroupContact);
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
    // avatar
hgs
parents:
diff changeset
   168
    QList<QContactAvatar> details = mGroupContact->details<QContactAvatar>();
hgs
parents:
diff changeset
   169
    for (int i = 0;i < details.count();i++)
hgs
parents:
diff changeset
   170
    {
hgs
parents:
diff changeset
   171
        if (details.at(i).imageUrl().isValid())
hgs
parents:
diff changeset
   172
            {
hgs
parents:
diff changeset
   173
            mAvatar = new QContactAvatar(details.at(i));
61
hgs
parents: 54
diff changeset
   174
            mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
54
hgs
parents:
diff changeset
   175
            break;
hgs
parents:
diff changeset
   176
            }
hgs
parents:
diff changeset
   177
    }
hgs
parents:
diff changeset
   178
    
hgs
parents:
diff changeset
   179
    // create list & model
hgs
parents:
diff changeset
   180
    mListView->setFrictionEnabled(true);
hgs
parents:
diff changeset
   181
    mListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
hgs
parents:
diff changeset
   182
    mListView->verticalScrollBar()->setInteractive(true);
hgs
parents:
diff changeset
   183
    mListView->setUniformItemSizes(true);
61
hgs
parents: 54
diff changeset
   184
    
hgs
parents: 54
diff changeset
   185
    HbFrameBackground frame;
hgs
parents: 54
diff changeset
   186
    frame.setFrameGraphicsName("qtg_fr_list_normal");
hgs
parents: 54
diff changeset
   187
    frame.setFrameType(HbFrameDrawer::NinePieces);
hgs
parents: 54
diff changeset
   188
        
hgs
parents: 54
diff changeset
   189
    HbListViewItem* prototype = mListView->listItemPrototype();
hgs
parents: 54
diff changeset
   190
    prototype->setGraphicsSize(HbListViewItem::Thumbnail);
hgs
parents: 54
diff changeset
   191
    prototype->setDefaultFrame(frame);
hgs
parents: 54
diff changeset
   192
    
54
hgs
parents:
diff changeset
   193
    HbIndexFeedback *indexFeedback = new HbIndexFeedback(mView);
hgs
parents:
diff changeset
   194
    indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
hgs
parents:
diff changeset
   195
    indexFeedback->setItemView(mListView);
hgs
parents:
diff changeset
   196
61
hgs
parents: 54
diff changeset
   197
    // if no contacts are present, then disable the Manage Members toolbar 
hgs
parents: 54
diff changeset
   198
    QContactDetailFilter filter;
hgs
parents: 54
diff changeset
   199
    filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
hgs
parents: 54
diff changeset
   200
    filter.setValue(QLatin1String(QContactType::TypeContact));
hgs
parents: 54
diff changeset
   201
   
hgs
parents: 54
diff changeset
   202
    QList<QContactLocalId> contactIds = getContactManager()->contactIds(filter);   
hgs
parents: 54
diff changeset
   203
    if (contactIds.isEmpty())
hgs
parents: 54
diff changeset
   204
    {
hgs
parents: 54
diff changeset
   205
       mManageAction->setEnabled(false); 
hgs
parents: 54
diff changeset
   206
    }      
54
hgs
parents:
diff changeset
   207
    
hgs
parents:
diff changeset
   208
    createModel();
hgs
parents:
diff changeset
   209
    
hgs
parents:
diff changeset
   210
    if (mArgs.value(ESelectedAction).toString() == CNT_SAVE_ACTION)
hgs
parents:
diff changeset
   211
    {
hgs
parents:
diff changeset
   212
        QString name = getContactManager()->synthesizedContactDisplayLabel(*mGroupContact);
hgs
parents:
diff changeset
   213
        HbNotificationDialog::launchDialog(HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_new_group_1_created").arg(name)));
hgs
parents:
diff changeset
   214
    }
hgs
parents:
diff changeset
   215
}
hgs
parents:
diff changeset
   216
hgs
parents:
diff changeset
   217
void CntGroupMemberViewPrivate::deactivate()
hgs
parents:
diff changeset
   218
{
hgs
parents:
diff changeset
   219
}
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
void CntGroupMemberViewPrivate::showPreviousView()
hgs
parents:
diff changeset
   222
{
hgs
parents:
diff changeset
   223
    Q_Q(CntGroupMemberView);
hgs
parents:
diff changeset
   224
    
hgs
parents:
diff changeset
   225
    emit q->backPressed();
hgs
parents:
diff changeset
   226
    
hgs
parents:
diff changeset
   227
    //save the contact if avatar has been changed.
61
hgs
parents: 54
diff changeset
   228
    QContact contact = getContactManager()->contact(mGroupContact->localId());
54
hgs
parents:
diff changeset
   229
    if ( contact != *mGroupContact )
hgs
parents:
diff changeset
   230
    {
hgs
parents:
diff changeset
   231
        getContactManager()->saveContact(mGroupContact);
hgs
parents:
diff changeset
   232
    }
hgs
parents:
diff changeset
   233
    mViewManager->back(mArgs);
hgs
parents:
diff changeset
   234
}
hgs
parents:
diff changeset
   235
hgs
parents:
diff changeset
   236
void CntGroupMemberViewPrivate::openGroupActions()
hgs
parents:
diff changeset
   237
{
hgs
parents:
diff changeset
   238
    QVariant var;
hgs
parents:
diff changeset
   239
    var.setValue(*mGroupContact);
hgs
parents:
diff changeset
   240
    
hgs
parents:
diff changeset
   241
    mArgs.insert(EViewId, groupActionsView);
hgs
parents:
diff changeset
   242
    mArgs.insert(ESelectedGroupContact, var);
hgs
parents:
diff changeset
   243
    mViewManager->changeView(mArgs);
hgs
parents:
diff changeset
   244
}
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
void CntGroupMemberViewPrivate::manageMembers()
hgs
parents:
diff changeset
   247
{
hgs
parents:
diff changeset
   248
    QContactRelationshipFilter membersFilter;
hgs
parents:
diff changeset
   249
    membersFilter.setRelationshipType(QContactRelationship::HasMember);
hgs
parents:
diff changeset
   250
    membersFilter.setRelatedContactRole(QContactRelationship::First);
hgs
parents:
diff changeset
   251
    membersFilter.setRelatedContactId(mGroupContact->id());   
hgs
parents:
diff changeset
   252
    
hgs
parents:
diff changeset
   253
    mOriginalGroupMembers = getContactManager()->contactIds(membersFilter);
hgs
parents:
diff changeset
   254
    
hgs
parents:
diff changeset
   255
    QContactName contactName = mGroupContact->detail( QContactName::DefinitionName );
hgs
parents:
diff changeset
   256
    QString groupName = contactName.value( QContactName::FieldCustomLabel );
hgs
parents:
diff changeset
   257
    if (groupName.isEmpty())
hgs
parents:
diff changeset
   258
    {
hgs
parents:
diff changeset
   259
        groupName = hbTrId("txt_phob_list_unnamed");
hgs
parents:
diff changeset
   260
    }
hgs
parents:
diff changeset
   261
    
hgs
parents:
diff changeset
   262
    CntFetchContactPopup* popup = CntFetchContactPopup::createMultiSelectionPopup(
hgs
parents:
diff changeset
   263
            HbParameterLengthLimiter(hbTrId("txt_phob_title_members_of_1_group")).arg(groupName),
hgs
parents:
diff changeset
   264
            hbTrId("txt_common_button_save"),
61
hgs
parents: 54
diff changeset
   265
            mEngine->contactManager(SYMBIAN_BACKEND));
54
hgs
parents:
diff changeset
   266
    connect( popup, SIGNAL(fetchReady(QSet<QContactLocalId>)),this, SLOT(handleManageMembers(QSet<QContactLocalId>)) );
hgs
parents:
diff changeset
   267
    popup->setSelectedContacts( mOriginalGroupMembers.toSet() );
hgs
parents:
diff changeset
   268
    popup->showPopup();
hgs
parents:
diff changeset
   269
}
hgs
parents:
diff changeset
   270
hgs
parents:
diff changeset
   271
void CntGroupMemberViewPrivate::handleManageMembers( QSet<QContactLocalId> aIds )
hgs
parents:
diff changeset
   272
{
hgs
parents:
diff changeset
   273
    QList<QContactRelationship> removedMemberships;
hgs
parents:
diff changeset
   274
    QList<QContactRelationship> addedMemberships;
hgs
parents:
diff changeset
   275
hgs
parents:
diff changeset
   276
    QSet<QContactLocalId> removedMembers = mOriginalGroupMembers.toSet() - aIds;
hgs
parents:
diff changeset
   277
    setRelationship(removedMembers, removedMemberships);
hgs
parents:
diff changeset
   278
hgs
parents:
diff changeset
   279
    QSet<QContactLocalId> addedMembers = aIds - mOriginalGroupMembers.toSet();
hgs
parents:
diff changeset
   280
    setRelationship(addedMembers, addedMemberships);
hgs
parents:
diff changeset
   281
    
hgs
parents:
diff changeset
   282
    if (!addedMemberships.isEmpty()) 
hgs
parents:
diff changeset
   283
    {
61
hgs
parents: 54
diff changeset
   284
        getContactManager()->saveRelationships(&addedMemberships, NULL);
54
hgs
parents:
diff changeset
   285
    }
hgs
parents:
diff changeset
   286
    
hgs
parents:
diff changeset
   287
    if (!removedMemberships.isEmpty()) 
hgs
parents:
diff changeset
   288
    {
61
hgs
parents: 54
diff changeset
   289
        getContactManager()->removeRelationships(removedMemberships, NULL);
54
hgs
parents:
diff changeset
   290
    }
hgs
parents:
diff changeset
   291
}
hgs
parents:
diff changeset
   292
hgs
parents:
diff changeset
   293
void CntGroupMemberViewPrivate::createModel()
hgs
parents:
diff changeset
   294
{
hgs
parents:
diff changeset
   295
    QContactRelationshipFilter rFilter;
hgs
parents:
diff changeset
   296
    rFilter.setRelationshipType(QContactRelationship::HasMember);
hgs
parents:
diff changeset
   297
    rFilter.setRelatedContactRole(QContactRelationship::First);
hgs
parents:
diff changeset
   298
    rFilter.setRelatedContactId(mGroupContact->id());
61
hgs
parents: 54
diff changeset
   299
    
54
hgs
parents:
diff changeset
   300
    mModel = new CntListModel(getContactManager(), rFilter, false);
hgs
parents:
diff changeset
   301
    mListView->setModel(mModel);
hgs
parents:
diff changeset
   302
}
hgs
parents:
diff changeset
   303
hgs
parents:
diff changeset
   304
void CntGroupMemberViewPrivate::editGroup()
hgs
parents:
diff changeset
   305
{
hgs
parents:
diff changeset
   306
    mArgs.insert(EViewId, groupEditorView);
hgs
parents:
diff changeset
   307
    QVariant var;
hgs
parents:
diff changeset
   308
    var.setValue(*mGroupContact);
hgs
parents:
diff changeset
   309
    mArgs.insert(ESelectedGroupContact, var);
hgs
parents:
diff changeset
   310
    mViewManager->changeView(mArgs);
hgs
parents:
diff changeset
   311
}
hgs
parents:
diff changeset
   312
hgs
parents:
diff changeset
   313
void CntGroupMemberViewPrivate::deleteGroup()
hgs
parents:
diff changeset
   314
{
hgs
parents:
diff changeset
   315
    QContactName contactName = mGroupContact->detail( QContactName::DefinitionName );
hgs
parents:
diff changeset
   316
    QString groupName = contactName.value( QContactName::FieldCustomLabel );
hgs
parents:
diff changeset
   317
    if (groupName.isNull())
hgs
parents:
diff changeset
   318
    {
hgs
parents:
diff changeset
   319
        groupName = hbTrId("txt_phob_list_unnamed");
hgs
parents:
diff changeset
   320
    }
hgs
parents:
diff changeset
   321
    
hgs
parents:
diff changeset
   322
    HbLabel *headingLabel = new HbLabel();
hgs
parents:
diff changeset
   323
    headingLabel->setPlainText(HbParameterLengthLimiter(hbTrId("txt_phob_dialog_delete_1_group")).arg(groupName));
hgs
parents:
diff changeset
   324
    
hgs
parents:
diff changeset
   325
    HbMessageBox::question(hbTrId("txt_phob_dialog_only_group_will_be_removed_contac"), this, SLOT(handleDeleteGroup(int)),
hgs
parents:
diff changeset
   326
            HbMessageBox::Delete | HbMessageBox::Cancel, headingLabel);
hgs
parents:
diff changeset
   327
}
hgs
parents:
diff changeset
   328
hgs
parents:
diff changeset
   329
void CntGroupMemberViewPrivate::handleDeleteGroup(int action)
hgs
parents:
diff changeset
   330
{
hgs
parents:
diff changeset
   331
    if (action == HbMessageBox::Delete)
hgs
parents:
diff changeset
   332
    {
hgs
parents:
diff changeset
   333
        getContactManager()->removeContact(mGroupContact->localId());
hgs
parents:
diff changeset
   334
        showPreviousView();
hgs
parents:
diff changeset
   335
    }
hgs
parents:
diff changeset
   336
}
hgs
parents:
diff changeset
   337
hgs
parents:
diff changeset
   338
/*!
hgs
parents:
diff changeset
   339
Called when a list item is longpressed
hgs
parents:
diff changeset
   340
*/
hgs
parents:
diff changeset
   341
void CntGroupMemberViewPrivate::showContextMenu(HbAbstractViewItem *aItem, const QPointF &aCoords)
hgs
parents:
diff changeset
   342
{
hgs
parents:
diff changeset
   343
    QVariant data( aItem->modelIndex().row() );
hgs
parents:
diff changeset
   344
   
hgs
parents:
diff changeset
   345
    QModelIndex index = aItem->modelIndex();
hgs
parents:
diff changeset
   346
hgs
parents:
diff changeset
   347
    HbMenu *menu = new HbMenu();
hgs
parents:
diff changeset
   348
    menu->setAttribute(Qt::WA_DeleteOnClose);
hgs
parents:
diff changeset
   349
    menu->setPreferredPos( aCoords );
hgs
parents:
diff changeset
   350
    
hgs
parents:
diff changeset
   351
    HbAction *removeFromGroupAction = 0;
hgs
parents:
diff changeset
   352
    HbAction *openContactAction = 0;
hgs
parents:
diff changeset
   353
    HbAction *editContactAction = 0;
hgs
parents:
diff changeset
   354
    HbAction *sendToHsAction = 0;
hgs
parents:
diff changeset
   355
hgs
parents:
diff changeset
   356
    openContactAction = menu->addAction(hbTrId("txt_common_menu_open"));
hgs
parents:
diff changeset
   357
    editContactAction = menu->addAction(hbTrId("txt_common_menu_edit"));
hgs
parents:
diff changeset
   358
    removeFromGroupAction = menu->addAction(hbTrId("txt_phob_menu_remove_from_group"));
hgs
parents:
diff changeset
   359
    sendToHsAction = menu->addAction(hbTrId("txt_phob_menu_send_to_homescreen"));
hgs
parents:
diff changeset
   360
    
hgs
parents:
diff changeset
   361
    openContactAction->setData( data );
hgs
parents:
diff changeset
   362
    editContactAction->setData( data );
hgs
parents:
diff changeset
   363
    removeFromGroupAction->setData( data );
hgs
parents:
diff changeset
   364
    sendToHsAction->setData( data );
hgs
parents:
diff changeset
   365
hgs
parents:
diff changeset
   366
    menu->open(this, SLOT(handleMenu(HbAction*)));
hgs
parents:
diff changeset
   367
}
hgs
parents:
diff changeset
   368
hgs
parents:
diff changeset
   369
void CntGroupMemberViewPrivate::handleMenu(HbAction* action)
hgs
parents:
diff changeset
   370
{
hgs
parents:
diff changeset
   371
    int row = action->data().toInt();
hgs
parents:
diff changeset
   372
    HbMenu *menuItem = static_cast<HbMenu*>(sender());
hgs
parents:
diff changeset
   373
    QModelIndex index = mModel->index(row);
hgs
parents:
diff changeset
   374
    
hgs
parents:
diff changeset
   375
    if ( action == menuItem->actions().first() )
hgs
parents:
diff changeset
   376
        {
hgs
parents:
diff changeset
   377
        showContactView(index);
hgs
parents:
diff changeset
   378
        }
hgs
parents:
diff changeset
   379
    else if (action == menuItem->actions().at(1))
hgs
parents:
diff changeset
   380
        {
hgs
parents:
diff changeset
   381
        editContact(index);
hgs
parents:
diff changeset
   382
        }
hgs
parents:
diff changeset
   383
    else if (action == menuItem->actions().at(2))
hgs
parents:
diff changeset
   384
        {
hgs
parents:
diff changeset
   385
        removeFromGroup(index);
hgs
parents:
diff changeset
   386
        }
hgs
parents:
diff changeset
   387
    else if (action == menuItem->actions().at(3))
hgs
parents:
diff changeset
   388
        {
hgs
parents:
diff changeset
   389
        sendToHs(index);
hgs
parents:
diff changeset
   390
        }
hgs
parents:
diff changeset
   391
}
hgs
parents:
diff changeset
   392
hgs
parents:
diff changeset
   393
/*!
hgs
parents:
diff changeset
   394
Called after user clicked on the listview.
hgs
parents:
diff changeset
   395
*/
hgs
parents:
diff changeset
   396
void CntGroupMemberViewPrivate::sendToHs(const QModelIndex &index)
hgs
parents:
diff changeset
   397
{
hgs
parents:
diff changeset
   398
    QVariantHash preferences;
hgs
parents:
diff changeset
   399
    preferences["contactId"] = mModel->contact(index).id().localId();
hgs
parents:
diff changeset
   400
    
hgs
parents:
diff changeset
   401
    XQServiceRequest snd("com.nokia.symbian.IHomeScreenClient",
hgs
parents:
diff changeset
   402
                         "addWidget(QString,QVariantHash)",
hgs
parents:
diff changeset
   403
                         false);
hgs
parents:
diff changeset
   404
    snd << QString("contactwidgethsplugin");
hgs
parents:
diff changeset
   405
    snd << preferences;
hgs
parents:
diff changeset
   406
    snd.send();
hgs
parents:
diff changeset
   407
}
hgs
parents:
diff changeset
   408
hgs
parents:
diff changeset
   409
/*!
hgs
parents:
diff changeset
   410
Called after user clicked on the listview.
hgs
parents:
diff changeset
   411
*/
hgs
parents:
diff changeset
   412
void CntGroupMemberViewPrivate::showContactView(const QModelIndex &index)
hgs
parents:
diff changeset
   413
{
hgs
parents:
diff changeset
   414
    mArgs.insert(EViewId, contactCardView);
hgs
parents:
diff changeset
   415
    QVariant var;
hgs
parents:
diff changeset
   416
    var.setValue(mModel->contact(index));
hgs
parents:
diff changeset
   417
    mArgs.insert(ESelectedContact, var);
hgs
parents:
diff changeset
   418
    QVariant varGroup;
hgs
parents:
diff changeset
   419
    varGroup.setValue(*mGroupContact);
hgs
parents:
diff changeset
   420
    mArgs.insert(ESelectedGroupContact, varGroup);
hgs
parents:
diff changeset
   421
    mViewManager->changeView(mArgs);
hgs
parents:
diff changeset
   422
        
hgs
parents:
diff changeset
   423
}
hgs
parents:
diff changeset
   424
hgs
parents:
diff changeset
   425
void CntGroupMemberViewPrivate::removeFromGroup(const QModelIndex &index)
hgs
parents:
diff changeset
   426
{
hgs
parents:
diff changeset
   427
    // get contact id using index
hgs
parents:
diff changeset
   428
    QContact selectedContact = mModel->contact(index);
hgs
parents:
diff changeset
   429
    QContactRelationship relationship;
hgs
parents:
diff changeset
   430
    relationship.setRelationshipType(QContactRelationship::HasMember);
hgs
parents:
diff changeset
   431
    relationship.setFirst(mGroupContact->id());
hgs
parents:
diff changeset
   432
    relationship.setSecond(selectedContact.id());
hgs
parents:
diff changeset
   433
    getContactManager()->removeRelationship(relationship);
hgs
parents:
diff changeset
   434
}
hgs
parents:
diff changeset
   435
hgs
parents:
diff changeset
   436
void CntGroupMemberViewPrivate::editContact(const QModelIndex &index)
hgs
parents:
diff changeset
   437
{
hgs
parents:
diff changeset
   438
hgs
parents:
diff changeset
   439
    mArgs.insert(EViewId, editView);
hgs
parents:
diff changeset
   440
    QVariant var;
hgs
parents:
diff changeset
   441
    var.setValue(mModel->contact(index));
hgs
parents:
diff changeset
   442
    mArgs.insert(ESelectedContact, var);
hgs
parents:
diff changeset
   443
    mViewManager->changeView(mArgs);
hgs
parents:
diff changeset
   444
}
hgs
parents:
diff changeset
   445
hgs
parents:
diff changeset
   446
void CntGroupMemberViewPrivate::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
hgs
parents:
diff changeset
   447
{
hgs
parents:
diff changeset
   448
    Q_UNUSED(data);
hgs
parents:
diff changeset
   449
    Q_UNUSED(id);
hgs
parents:
diff changeset
   450
    Q_UNUSED(error);
hgs
parents:
diff changeset
   451
    if (!error)
hgs
parents:
diff changeset
   452
    {
hgs
parents:
diff changeset
   453
        HbIcon icon(pixmap);
hgs
parents:
diff changeset
   454
        mHeadingItem->setIcon(icon);
hgs
parents:
diff changeset
   455
        
hgs
parents:
diff changeset
   456
        mImageLabel->clear();
hgs
parents:
diff changeset
   457
        mImageLabel->setIcon(pixmap);
hgs
parents:
diff changeset
   458
    }
hgs
parents:
diff changeset
   459
}
hgs
parents:
diff changeset
   460
hgs
parents:
diff changeset
   461
void CntGroupMemberViewPrivate::openImageEditor()
hgs
parents:
diff changeset
   462
{
hgs
parents:
diff changeset
   463
    QVariant var;
hgs
parents:
diff changeset
   464
    var.setValue(*mGroupContact);
hgs
parents:
diff changeset
   465
       
hgs
parents:
diff changeset
   466
    // only group contact is assigned since we want to only
hgs
parents:
diff changeset
   467
    // change the groups image
hgs
parents:
diff changeset
   468
    mArgs.insert(ESelectedGroupContact, var);
hgs
parents:
diff changeset
   469
    
hgs
parents:
diff changeset
   470
    mArgs.insert(EViewId, imageEditorView );
hgs
parents:
diff changeset
   471
        
hgs
parents:
diff changeset
   472
    mViewManager->changeView( mArgs );
hgs
parents:
diff changeset
   473
}
hgs
parents:
diff changeset
   474
hgs
parents:
diff changeset
   475
QContactManager* CntGroupMemberViewPrivate::getContactManager()
hgs
parents:
diff changeset
   476
{
61
hgs
parents: 54
diff changeset
   477
    return &mEngine->contactManager(SYMBIAN_BACKEND);
54
hgs
parents:
diff changeset
   478
}
hgs
parents:
diff changeset
   479
61
hgs
parents: 54
diff changeset
   480
void CntGroupMemberViewPrivate::setRelationship(QSet<QContactLocalId>        &aLocalIds,
54
hgs
parents:
diff changeset
   481
                                         QList<QContactRelationship>  &aRelationshipList)
hgs
parents:
diff changeset
   482
{
61
hgs
parents: 54
diff changeset
   483
    foreach (QContactLocalId localId, aLocalIds) {
hgs
parents: 54
diff changeset
   484
		QContactId id;
hgs
parents: 54
diff changeset
   485
		id.setLocalId(localId);
54
hgs
parents:
diff changeset
   486
        QContactRelationship membership;
hgs
parents:
diff changeset
   487
        membership.setRelationshipType(QContactRelationship::HasMember);
hgs
parents:
diff changeset
   488
        membership.setFirst(mGroupContact->id());
61
hgs
parents: 54
diff changeset
   489
        membership.setSecond(id);
54
hgs
parents:
diff changeset
   490
        aRelationshipList.append(membership);
hgs
parents:
diff changeset
   491
    }
hgs
parents:
diff changeset
   492
}
hgs
parents:
diff changeset
   493
hgs
parents:
diff changeset
   494
/*!
hgs
parents:
diff changeset
   495
Draw the image specific content menu
hgs
parents:
diff changeset
   496
*/
hgs
parents:
diff changeset
   497
void CntGroupMemberViewPrivate::drawImageMenu(const QPointF &aCoords)
hgs
parents:
diff changeset
   498
{
hgs
parents:
diff changeset
   499
    HbMenu *menu = new HbMenu();
hgs
parents:
diff changeset
   500
    HbAction *changeImageAction = menu->addAction(hbTrId("txt_phob_menu_change_picture"), this, SLOT(openImageEditor()));
hgs
parents:
diff changeset
   501
    if (mAvatar && !mAvatar->imageUrl().isEmpty())
hgs
parents:
diff changeset
   502
    {
61
hgs
parents: 54
diff changeset
   503
        menu->addAction(hbTrId("txt_phob_menu_remove_image"), this, SLOT(removeImage()));
54
hgs
parents:
diff changeset
   504
    }
hgs
parents:
diff changeset
   505
    menu->setPreferredPos(aCoords);
hgs
parents:
diff changeset
   506
    menu->open();
hgs
parents:
diff changeset
   507
}
hgs
parents:
diff changeset
   508
hgs
parents:
diff changeset
   509
hgs
parents:
diff changeset
   510
void CntGroupMemberViewPrivate::removeImage()
hgs
parents:
diff changeset
   511
{
hgs
parents:
diff changeset
   512
    if (mAvatar) 
hgs
parents:
diff changeset
   513
    {
hgs
parents:
diff changeset
   514
        if (!mAvatar->imageUrl().isEmpty())
hgs
parents:
diff changeset
   515
        {
hgs
parents:
diff changeset
   516
            bool success = mGroupContact->removeDetail(mAvatar);
hgs
parents:
diff changeset
   517
            // Check if image removable.
hgs
parents:
diff changeset
   518
            CntImageUtility imageUtility;
hgs
parents:
diff changeset
   519
            if(imageUtility.isImageRemovable(mAvatar->imageUrl().toString()))
hgs
parents:
diff changeset
   520
            {
hgs
parents:
diff changeset
   521
                imageUtility.removeImage(mAvatar->imageUrl().toString());
hgs
parents:
diff changeset
   522
            }
hgs
parents:
diff changeset
   523
            mAvatar->setImageUrl(QUrl());
hgs
parents:
diff changeset
   524
            mImageLabel->clear();
hgs
parents:
diff changeset
   525
            mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_group_picture"));
hgs
parents:
diff changeset
   526
            mHeadingItem->setIcon(HbIcon("qtg_large_add_group_picture"));
hgs
parents:
diff changeset
   527
            getContactManager()->saveContact(mGroupContact);
hgs
parents:
diff changeset
   528
       }
hgs
parents:
diff changeset
   529
    }
hgs
parents:
diff changeset
   530
}
hgs
parents:
diff changeset
   531
hgs
parents:
diff changeset
   532
hgs
parents:
diff changeset
   533
hgs
parents:
diff changeset
   534
// end of file