Skip to content

Commit

Permalink
Big changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseysidorov committed Jun 16, 2012
1 parent 8350c7a commit 29fa338
Show file tree
Hide file tree
Showing 28 changed files with 425 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .directory
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[Dolphin]
Timestamp=2012,4,19,13,5,47
Timestamp=2012,6,16,20,11,44
Version=3
3 changes: 2 additions & 1 deletion NonameIM.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ TEMPLATE= subdirs
CONFIG += ordered

SUBDIRS += vk \
src
src \
feed

OTHER_FILES += \
qtc_packaging/debian_harmattan/rules \
Expand Down
3 changes: 3 additions & 0 deletions feed/client/nonameim.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<profile name="nonameim" type="client" >
</profile>
3 changes: 3 additions & 0 deletions feed/dbus/org.nonameim..service
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D-BUS Service]
Name=org.nonameim
Exec=/usr/bin/invoker --splash=/opt/nonameIM/share/splash/portrait.png --splash-landscape=/opt/nonameIM/share/splash/landscape.png --single-instance --type=e /opt/nonameIM/bin/nonameIM
50 changes: 50 additions & 0 deletions feed/feed.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
TEMPLATE = lib
TARGET = nonameim-client
DEPENDPATH += .
INCLUDEPATH += . \
/usr/include/libsynccommon \
/usr/include/libsyncprofile \
/usr/include/gq \
$$PWD/../vk/src/api
DEPENDPATH += $$PWD/../vk/src/api
LIBS += -lsyncpluginmgr -lsyncprofile -lgq-gconf -L$$OUT_PWD/../vk/src/api/ -lvk

CONFIG += debug plugin meegotouchevents

QT += dbus network
QT -= gui

QMAKE_CXXFLAGS = -Wall \
-g \
-Wno-cast-align \
-O2 -finline-functions

#install
target.path = /usr/lib/sync/

client.path = /etc/sync/profiles/client
client.files = client/nonameim.xml

sync.path = /etc/sync/profiles/sync
sync.files = sync/*

service.path = /etc/sync/profiles/service
service.files = service/*

settingsdesktop.path = /usr/share/duicontrolpanel/desktops
settingsdesktop.files = settings/nonameim.desktop

settingsxml.path = /usr/share/duicontrolpanel/uidescriptions
settingsxml.files = settings/nonameim.xml

INSTALLS += target client sync service settingsdesktop settingsxml

HEADERS += \
newsfeed_client.h

SOURCES += \
newsfeed_client.cpp

!isEmpty(MEEGO_VERSION_MAJOR) {
QMAKE_LFLAGS += -Wl,--rpath=/opt/nonameIM/lib
}
144 changes: 144 additions & 0 deletions feed/newsfeed_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#include "newsfeed_client.h"
#include <QSettings>
#include <client.h>
#include <gconfitem.h>
#include <meventfeed.h>
#include <roster.h>
#include <attachment.h>

extern "C" NewsFeedClient* createPlugin(const QString& aPluginName,
const Buteo::SyncProfile& aProfile,
Buteo::PluginCbInterface *aCbInterface)
{
return new NewsFeedClient(aPluginName, aProfile, aCbInterface);
}

extern "C" void destroyPlugin(NewsFeedClient *aClient)
{
delete aClient;
}

NewsFeedClient::NewsFeedClient(const QString &aPluginName, const Buteo::SyncProfile &aProfile, Buteo::PluginCbInterface *aCbInterface) :
Buteo::ClientPlugin(aPluginName, aProfile, aCbInterface)
{
}

NewsFeedClient::~NewsFeedClient()
{
}

bool NewsFeedClient::init()
{
m_client = new vk::Client(this);
m_feed = new vk::NewsFeed(m_client.data());

connect(m_feed.data(), SIGNAL(newsRecieved(vk::NewsItemList)), SLOT(newsRecieved(vk::NewsItemList)));
connect(m_client.data(), SIGNAL(onlineStateChanged(bool)), SLOT(connectedToHost(bool)));
return true;
}

bool NewsFeedClient::uninit()
{
m_client.data()->deleteLater();
return true;
}

bool NewsFeedClient::startSync()
{
//GConfItem enabledConfItem("/apps/ControlPanel/NonameIM/EnableFeed");
//QVariant enabledVariant = enabledConfItem.value();

//if (enabledVariant.isValid()) {
// bool enabled = enabledVariant.toBool();
// if (!enabled) {
// MEventFeed::instance()->removeItemsBySourceName("SyncFW-nonameim");
// return false;
// }
//} else {
// enabledConfItem.set(true);
//}

QSettings settings("noname", "nonameIM");
settings.beginGroup("connection");
QString login = settings.value("login").toString();
QString password = settings.value("password").toString();
settings.endGroup();
if (login.isEmpty() || password.isEmpty())
return false;

m_client.data()->setPassword(password);
m_client.data()->setLogin(login);
return true;
}

void NewsFeedClient::abortSync(Sync::SyncStatus aStatus)
{
Q_UNUSED(aStatus);
}

Buteo::SyncResults NewsFeedClient::getSyncResults() const
{
return m_results;
}

bool NewsFeedClient::cleanUp()
{
return true;
}

void NewsFeedClient::connectivityStateChanged(Sync::ConnectivityType aType, bool aState)
{
Q_UNUSED(aType);
if (aState)
m_client.data()->connectToHost();
}

void NewsFeedClient::newsRecieved(const vk::NewsItemList &news)
{
foreach (vk::NewsItem item, news) {
vk::Contact *from = m_client.data()->roster()->contact(item.sourceId());
vk::Attachment::List attachments = item.attachments(vk::Attachment::Photo);
QStringList list;
foreach (vk::Attachment attach, attachments)
list.append(attach.property("src").toString());

MEventFeed::instance()->addItem(from->photoSource(),
from->name(),
item.body(),
list,
item.date(),
QString(),
false,
QUrl(),
QString("SyncFW-nonameim"),
QString("NonameIM")
);
}
MEventFeed::instance()->removeItemsBySourceName("SyncFW-nonameim");
}

void NewsFeedClient::connectedToHost(bool success)
{
if (success) {
m_feed.data()->getNews(vk::NewsFeed::FilterPost | vk::NewsFeed::FilterPhoto); //TODO add offset check and others
}
}

void NewsFeedClient::syncSuccess()
{
updateResults(Buteo::SyncResults(QDateTime::currentDateTime(), Buteo::SyncResults::SYNC_RESULT_SUCCESS, Buteo::SyncResults::NO_ERROR));
emit success(getProfileName(), "Success!!");
}

void NewsFeedClient::syncFailed()
{
updateResults(Buteo::SyncResults(QDateTime::currentDateTime(),
Buteo::SyncResults::SYNC_RESULT_FAILED, Buteo::SyncResults::ABORTED));
emit error(getProfileName(), "Error!!", Buteo::SyncResults::SYNC_RESULT_FAILED);
}

void NewsFeedClient::updateResults(const Buteo::SyncResults &aResults)
{
m_results = aResults;
m_results.setScheduled(true);
}
48 changes: 48 additions & 0 deletions feed/newsfeed_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef NEWSFEEDCLIENT_H
#define NEWSFEEDCLIENT_H

#include <libsyncpluginmgr/ClientPlugin.h>
#include <libsyncprofile/SyncResults.h>
#include <QWeakPointer>
#include <newsitem.h>
#include <newsfeed.h>

class NewsFeedClient : public Buteo::ClientPlugin
{
Q_OBJECT
public:
NewsFeedClient( const QString& aPluginName,
const Buteo::SyncProfile& aProfile,
Buteo::PluginCbInterface *aCbInterface );

virtual ~NewsFeedClient();
virtual bool init();
virtual bool uninit();
virtual bool startSync();
virtual void abortSync(Sync::SyncStatus aStatus = Sync::SYNC_ABORTED);
virtual Buteo::SyncResults getSyncResults() const;
virtual bool cleanUp();
public slots:
virtual void connectivityStateChanged(Sync::ConnectivityType aType,
bool aState);

protected slots:
void newsRecieved(const vk::NewsItemList &news);
void connectedToHost(bool success);
void syncSuccess();
void syncFailed();
private:
void updateResults(const Buteo::SyncResults &aResults);
private:
Buteo::SyncResults m_results;
QWeakPointer<vk::Client> m_client;
QWeakPointer<vk::NewsFeed> m_feed;
};

extern "C" NewsFeedClient* createPlugin(const QString& aPluginName,
const Buteo::SyncProfile& aProfile,
Buteo::PluginCbInterface *aCbInterface);

extern "C" void destroyPlugin(NewsFeedClient *aClient);

#endif // NEWSFEEDCLIENT_H
6 changes: 6 additions & 0 deletions feed/service/nonameim.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<profile name="nonameim" type="service">
<key name="destinationtype" value="device"/>
<profile name="nonameim" type="client" >
</profile>
</profile>
14 changes: 14 additions & 0 deletions feed/settings/nonameim.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Desktop Entry]
Type=ControlPanelApplet
Name=NonameIM
Exec=
X-logical-id=qtn_noname_events_feed
X-translation-catalog=nonameim

[DUI]
X-DUIApplet-Applet=libdeclarative.so

[DCP]
Category=Events Feed
Order=100
Part=nonameim.xml
3 changes: 3 additions & 0 deletions feed/settings/nonameim.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<settings>
<boolean key="/apps/ControlPanel/NonameIM/EnableFeed" title="Publish to Feed"></boolean>
</settings>
11 changes: 11 additions & 0 deletions feed/sync/nonameim.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<profile name="nonameim" type="sync" >
<key name="displayname" value="NonameIM"/>
<key name="enabled" value="true" />
<key name="use_accounts" value="false" />
<key name="hidden" value="true" />
<profile type="service" name="nonameim" >
</profile>
<schedule enabled="true" interval="30" days="1,2,3,4,5,6,7" syncconfiguredtime="" time="">
</schedule>
</profile>
6 changes: 6 additions & 0 deletions qtc_packaging/debian_harmattan/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

/usr/bin/aegis-exec -s -u user dbus-send --dest=com.meego.msyncd --print-reply /synchronizer com.meego.msyncd.installPlugin string:'nonameim'

# Make sure the installation is always considered successful
exit 0
9 changes: 9 additions & 0 deletions qtc_packaging/debian_harmattan/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

/usr/bin/aegis-exec -s -u user dbus-send --dest=com.meego.msyncd --print-reply /synchronizer com.meego.msyncd.uninstallPlugin string:'nonameim'

# Clean up the feed items published by this application
/usr/bin/aegis-exec -s -u user dbus-send --dest=com.nokia.home.NonameIM --print-reply /eventfeed com.nokia.home.NonameIM.removeItemsBySourceName string:'SyncFW-event-nonameim'

# Make sure the uninstallation is always considered successful
exit 0
19 changes: 19 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@
#include <longpoll.h>
#include <attachment.h>
#include <newsfeed.h>
#include <QNetworkDiskCache>

#define VK_API_NAMESPACE "com.vk.api"

class DiskNetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory
{
public:
virtual QNetworkAccessManager *create(QObject *parent);
};
QNetworkAccessManager *DiskNetworkAccessManagerFactory::create(QObject *parent)
{
QNetworkAccessManager *manager = new QNetworkAccessManager(parent);
QNetworkDiskCache *cache = new QNetworkDiskCache(manager);
cache->setCacheDirectory("nonameIM");
cache->setMaximumCacheSize(1024 * 1024 * 100);

qDebug() << "--NetworkCache directory " << cache->cacheDirectory();
qDebug() << "--NetworkCache size " << cache->cacheSize();
return manager;
}

Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
Expand All @@ -43,6 +61,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qmlRegisterUncreatableType<vk::NewsFeed>(VK_API_NAMESPACE, 0, 1, "NewsFeed", QObject::tr("NewsFeed enums"));

QmlApplicationViewer viewer;
viewer.engine()->setNetworkAccessManagerFactory(new DiskNetworkAccessManagerFactory);
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setMainQmlFile(QLatin1String("qml/harmattan/main.qml"));
viewer.showExpanded();
Expand Down
1 change: 1 addition & 0 deletions src/qml/harmattan/ChatPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Page {
highlight: HighlightDelegate {}
delegate: ChatDelegate {}
currentIndex: -1
cacheBuffer: 100500
}

ChatModel {
Expand Down
1 change: 1 addition & 0 deletions src/qml/harmattan/DialogsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Page {
}
}
currentIndex: -1
cacheBuffer: 100500
}

ScrollDecorator {
Expand Down
1 change: 1 addition & 0 deletions src/qml/harmattan/NewsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Page {
width: parent.width
delegate: NewsDelegate {}
model: newsFeedModel
cacheBuffer: 100500
footer: UpdateIndicator {
visible: newsList.count
running: __isNextLoading
Expand Down
Loading

0 comments on commit 29fa338

Please sign in to comment.