Skip to content

Commit

Permalink
News speed up. Info banner initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseysidorov committed May 30, 2012
1 parent 142bd01 commit 9ffcd1e
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 16 deletions.
25 changes: 21 additions & 4 deletions src/newsfeedmodel.cpp
Expand Up @@ -21,6 +21,8 @@ NewsFeedModel::NewsFeedModel(QObject *parent) :
roles[RepostsRole] = "reposts";
roles[CommentsRole] = "comments";
roles[OwnerNameRole] = "ownerName";
roles[SourcePhotoRole] = "sourcePhoto";
roles[SourceNameRole] = "sourceName";
setRoleNames(roles);
}

Expand Down Expand Up @@ -57,7 +59,7 @@ QVariant NewsFeedModel::data(const QModelIndex &index, int role) const
break;
case SourceRole: {
int source = news.sourceId();
return qVariantFromValue(m_client.data()->roster()->contact(source));
return qVariantFromValue(findContact(source));
}
case DateRole:
return news.date();
Expand All @@ -79,6 +81,16 @@ QVariant NewsFeedModel::data(const QModelIndex &index, int role) const
}
return QVariant();
}
case SourcePhotoRole: {
if (auto contact = findContact(news.sourceId()))
return contact->photoSource();
break;
}
case SourceNameRole: {
if (auto contact = findContact(news.sourceId()))
return contact->name();
break;
}
default:
break;
}
Expand Down Expand Up @@ -123,10 +135,10 @@ void NewsFeedModel::clear()

void NewsFeedModel::truncate(int count)
{
if (count > m_newsList.count())
count = m_newsList.count();
if (count >= m_newsList.count())
count = m_newsList.count() - 1;

beginRemoveRows(QModelIndex(), 0, count);
beginRemoveRows(QModelIndex(), count, m_newsList.count() - 1);
m_newsList.erase(m_newsList.begin() + count - 1, m_newsList.end());
endRemoveRows();
}
Expand All @@ -153,3 +165,8 @@ void NewsFeedModel::insertNews(int index, const vk::NewsItem &item)
endInsertRows();
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
}

vk::Contact *NewsFeedModel::findContact(int id) const
{
return m_client.data()->roster()->contact(id);
}
9 changes: 8 additions & 1 deletion src/newsfeedmodel.h
Expand Up @@ -5,6 +5,10 @@
#include <newsfeed.h>
#include <QWeakPointer>

namespace vk {
class Contact;
} //namespace vk

class NewsFeedModel : public QAbstractListModel
{
Q_OBJECT
Expand All @@ -21,7 +25,9 @@ class NewsFeedModel : public QAbstractListModel
LikesRole,
RepostsRole,
CommentsRole,
OwnerNameRole
OwnerNameRole,
SourcePhotoRole,
SourceNameRole
};

explicit NewsFeedModel(QObject *parent = 0);
Expand All @@ -41,6 +47,7 @@ public slots:
void requestFinished();
protected:
void insertNews(int index, const vk::NewsItem &data);
vk::Contact *findContact(int id) const;
private slots:
void onNewsAdded(const vk::NewsItem &data);
private:
Expand Down
5 changes: 3 additions & 2 deletions src/qml/harmattan/NewsPage.qml
Expand Up @@ -9,8 +9,9 @@ Page {
id: newsPage

property int __offset: 0
property int __count: 10
property int __count: 30
property bool __isNextLoading: false
property int __truncateCount: 100

function update() {
if (client.online) {
Expand Down Expand Up @@ -63,7 +64,7 @@ Page {

onRequestFinished: {
if (!__offset)
truncate(__count)
truncate(__truncateCount)
__isNextLoading = false
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/qml/harmattan/components/NotifyStack.js
@@ -0,0 +1,21 @@
var notifyStack = []

function push(info)
{
notifyStack.push(info)
}

function pop()
{
return notifyStack.pop()
}

function top()
{
return notifyStack[0]
}

function deep()
{
return notifyStack.length
}
46 changes: 46 additions & 0 deletions src/qml/harmattan/components/StackedInfoBanner.qml
@@ -0,0 +1,46 @@
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import com.nokia.extras 1.1
import "NotifyStack.js" as NotifyStack

InfoBanner {
id: banner

function push(text, iconSource, callback) {
var item = {
"iconSource" : iconSource,
"text" : text,
"callback" : callback
}
__setInfo(item)
NotifyStack.push(item)
banner.show()
}

function pop() {
var item = NotifyStack.pop()
if (item.callback)
item.callback()
item = NotifyStack.top()
console.log(NotifyStack.deep())
if (item)
__setInfo(item)
else
banner.hide()
}

function __setInfo(item)
{
banner.text = item.text
banner.iconSource = item.iconSource
}

timerEnabled: false

MouseArea {
anchors.fill: parent
onClicked: {
banner.pop()
}
}
}
9 changes: 4 additions & 5 deletions src/qml/harmattan/delegates/NewsDelegate.qml
Expand Up @@ -9,8 +9,7 @@ import "../components"
ItemDelegate {
id: itemDelegate

//imageSource: Utils.getContactPhotoSource(source)
imageSource: source.photoSource
imageSource: sourcePhoto
item: data
__minHeight: 120

Expand All @@ -35,7 +34,7 @@ ItemDelegate {

Label {
id: titleLabel
text: source.name
text: sourceName
width: parent.width
color: "#2b497a"

Expand Down Expand Up @@ -128,8 +127,8 @@ ItemDelegate {
//}

PostInfo {
likes: typeof(model.likes.count !== "undefined") ? model.likes.count : 0
comments: typeof(model.comments.count !== "undefined") ? model.comments.count : 0
likes: typeof(model.likes !== "undefined") ? model.likes.count : 0
comments: typeof(model.comments !== "undefined") ? model.comments.count : 0
date: model.date
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/qml/harmattan/main.qml
@@ -1,6 +1,5 @@
import QtQuick 1.1
import com.nokia.meego 1.0
import com.nokia.extras 1.1
import com.vk.api 0.1
import "ios" as Ios
import "components"
Expand Down Expand Up @@ -46,6 +45,10 @@ PageStackWindow {
finish.connect(balloon.finished)
}

function sendNotify(text, iconSource, callback) {
infoBanner.push(text, iconSource, callback)
}

function connectToHost() {
addTask(qsTr("Connecting to vk..."), client.onlineStateChanged)
client.connectToHost()
Expand Down Expand Up @@ -134,6 +137,12 @@ PageStackWindow {
}
}

StackedInfoBanner {
id: infoBanner

topMargin: 120
leftMargin: 7
}

Client {
id: client
Expand All @@ -147,6 +156,7 @@ PageStackWindow {
} else {
pageStack.push(loginPage)
balloon.deep = 0
sendNotify(qsTr("Disconnected from host"))
}
}
}
Expand Down Expand Up @@ -213,7 +223,8 @@ PageStackWindow {
Connections {
target: client.longPoll ? client.longPoll : parent
onMessageAdded: {
messagesIcon.alert();
messagesIcon.alert()
sendNotify(qsTr("New message recieved"), "")
}
}
}
3 changes: 2 additions & 1 deletion src/src.pro
Expand Up @@ -62,7 +62,8 @@ OTHER_FILES += \
qtc_packaging/debian_harmattan/copyright \
qtc_packaging/debian_harmattan/control \
qtc_packaging/debian_harmattan/compat \
qtc_packaging/debian_harmattan/changelog
qtc_packaging/debian_harmattan/changelog \
qml/harmattan/components/NotifyStack.js

win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../vk/src/api/release/ -lvk
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../vk/src/api/debug/ -lvk
Expand Down
2 changes: 1 addition & 1 deletion vk
Submodule vk updated from 9b8d34 to fefd72

0 comments on commit 9ffcd1e

Please sign in to comment.