Commit e72d43ce authored by Sébastien Blin's avatar Sébastien Blin Committed by Nicolas Jager

conversationsview: add class to draw conversation items

- this class will replace recentcontactsview and
contactrequestcontentview.
- update pixbufmanipulator to draw conversations.

Change-Id: Id7011c7e275146213a8b542982b2a05c6f5ab98f
Reviewed-by: default avatarNicolas Jäger <nicolas.jager@savoirfairelinux.com>
parent 05752143
......@@ -334,6 +334,8 @@ SET( SRC_FILES
src/accountcontainer.h
src/conversationpopupmenu.h
src/conversationpopupmenu.cpp
src/conversationsview.h
src/conversationsview.cpp
)
# compile glib resource files to c code
......
This diff is collapsed.
/****************************************************************************
* Copyright (C) 2017 Savoir-faire Linux *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#pragma once
#include <gtk/gtk.h>
#include "accountcontainer.h"
G_BEGIN_DECLS
#define CONVERSATIONS_VIEW_TYPE (conversations_view_get_type ())
#define CONVERSATIONS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONVERSATIONS_VIEW_TYPE, ConversationsView))
#define CONVERSATIONS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CONVERSATIONS_VIEW_TYPE, ConversationsViewClass))
#define IS_CONVERSATIONS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CONVERSATIONS_VIEW_TYPE))
#define IS_CONVERSATIONS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CONVERSATIONS_VIEW_TYPE))
typedef struct _ConversationsView ConversationsView;
typedef struct _ConversationsViewClass ConversationsViewClass;
GType conversations_view_get_type (void) G_GNUC_CONST;
GtkWidget *conversations_view_new (AccountContainer* accountContainer);
void conversations_view_select_conversation (ConversationsView *self, const std::string& uid);
G_END_DECLS
/*
* Copyright (C) 2015-2017 Savoir-faire Linux Inc.
* Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -27,6 +28,16 @@
#include <call.h>
#include <contactmethod.h>
#include <string>
#include <algorithm>
// lrc
#include <api/contactmodel.h>
#include <api/conversation.h>
#include <api/account.h>
#include <api/contact.h>
namespace Interfaces {
PixbufManipulator::PixbufManipulator()
......@@ -70,6 +81,24 @@ PixbufManipulator::generateAvatar(const ContactMethod* cm) const
};
}
std::shared_ptr<GdkPixbuf>
PixbufManipulator::generateAvatar(const std::string& alias, const std::string& uri) const
{
auto name = alias;
std::transform(name.begin(), name.end(), name.begin(), ::toupper);
auto letter = name.length() > 0 ? name[0] : 'R';
auto color = uri.length() > 0 ? std::stoi(std::string(1, uri[0]), 0, 16) : 0;
return std::shared_ptr<GdkPixbuf> {
ring_draw_fallback_avatar(
FALLBACK_AVATAR_SIZE,
letter,
color
),
g_object_unref
};
}
std::shared_ptr<GdkPixbuf>
PixbufManipulator::scaleAndFrame(const GdkPixbuf *photo, const QSize& size, bool display_presence, bool is_present)
{
......@@ -203,6 +232,35 @@ QVariant PixbufManipulator::personPhoto(const QByteArray& data, const QString& t
return QVariant();
}
QVariant
PixbufManipulator::conversationPhoto(const lrc::api::conversation::Info& conversation,
const lrc::api::account::Info& accountInfo,
const QSize& size,
bool displayPresence)
{
auto contacts = conversation.participants;
if (!contacts.empty())
{
// Get first contact photo
auto contactUri = contacts.front();
auto contactInfo = accountInfo.contactModel->getContact(contactUri);
auto contactPhoto = contactInfo.profileInfo.avatar;
auto bestName = contactInfo.profileInfo.alias.empty()? contactInfo.registeredName : contactInfo.profileInfo.alias;
if (contactInfo.profileInfo.type == lrc::api::profile::Type::SIP) {
return QVariant::fromValue(scaleAndFrame(generateAvatar(bestName, "").get(), size, displayPresence, true));
} else if (!contactPhoto.empty()) {
QByteArray byteArray(contactPhoto.c_str(), contactPhoto.length());
QVariant photo = personPhoto(byteArray);
return QVariant::fromValue(scaleAndFrame(photo.value<std::shared_ptr<GdkPixbuf>>().get(), size, displayPresence, true));
} else {
return QVariant::fromValue(scaleAndFrame(generateAvatar(bestName, contactInfo.profileInfo.uri).get(), size, displayPresence, true));
}
}
// should not
return QVariant::fromValue(scaleAndFrame(generateAvatar("", "").get(), size, displayPresence, true));
}
QVariant
PixbufManipulator::numberCategoryIcon(const QVariant& p, const QSize& size, bool displayPresence, bool isPresent)
{
......@@ -309,4 +367,12 @@ QVariant PixbufManipulator::decorationRole(const Account* p)
return QVariant();
}
QVariant PixbufManipulator::decorationRole(const lrc::api::conversation::Info& conversation,
const lrc::api::account::Info& accountInfo)
{
Q_UNUSED(conversation)
Q_UNUSED(accountInfo)
return QVariant();
}
} // namespace Interfaces
......@@ -29,6 +29,10 @@ class Person;
namespace Interfaces {
/**
* TODO remove old methods (methods which use Call, ContactMethod, Person, etc)
* But before, they should be removed from PixmapManipulatorI
*/
class PixbufManipulator : public PixmapManipulatorI {
constexpr static int FALLBACK_AVATAR_SIZE {100};
public:
......@@ -36,10 +40,13 @@ public:
QVariant callPhoto(Call* c, const QSize& size, bool displayPresence = true) override;
QVariant callPhoto(const ContactMethod* n, const QSize& size, bool displayPresence = true) override;
QVariant conversationPhoto(const lrc::api::conversation::Info& conversation,
const lrc::api::account::Info& accountInfo,
const QSize& size,
bool displayPresence = true) override;
QVariant contactPhoto(Person* c, const QSize& size, bool displayPresence = true) override;
QVariant personPhoto(const QByteArray& data, const QString& type = "PNG") override;
/* TODO: the following methods return an empty QVariant/QByteArray */
QVariant numberCategoryIcon(const QVariant& p, const QSize& size, bool displayPresence = false, bool isPresent = false) override;
QVariant securityIssueIcon(const QModelIndex& index) override;
QByteArray toByteArray(const QVariant& pxm) override;
......@@ -52,10 +59,13 @@ public:
QVariant decorationRole(const Call* c) override;
QVariant decorationRole(const ContactMethod* cm) override;
QVariant decorationRole(const Person* p) override;
QVariant decorationRole(const lrc::api::conversation::Info& conversation,
const lrc::api::account::Info& accountInfo) override;
QVariant decorationRole(const Account* p) override;
private:
std::shared_ptr<GdkPixbuf> generateAvatar(const ContactMethod* cm) const;
std::shared_ptr<GdkPixbuf> generateAvatar(const std::string& alias, const std::string& uri) const;
std::shared_ptr<GdkPixbuf> scaleAndFrame(const GdkPixbuf *photo, const QSize& size, bool display_presence = false, bool is_present = false);
std::shared_ptr<GdkPixbuf> conferenceAvatar_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment