Skip to content

Commit

Permalink
Add support for custom path for received files
Browse files Browse the repository at this point in the history
Also begin working on resources improvements.
  • Loading branch information
ksiazkowicz committed Sep 28, 2014
1 parent 486340c commit 394f479
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 23 deletions.
1 change: 1 addition & 0 deletions platforms/global/qml/Globals.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Item {
property bool areEmoticonsDisabled: settings.gBool("behavior","disableEmoticons")
property int keepAliveInterval: settings.gInt("behavior","keepAliveInterval")
property string defaultMUCNick: settings.gStr("behavior","defaultMUCNick")
property string receivedFilesPath: settings.gStr("paths","recvFiles")

property bool isRestartRequired: false
property bool isBlinkingOverrideEnabled: false
Expand Down
39 changes: 39 additions & 0 deletions platforms/symbian.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,43 @@
<file alias="defaultSkin/errorIcon">symbian/images/convo/errorIcon.svg</file>
<file alias="defaultSkin/alertIcon">symbian/images/convo/alertIcon.svg</file>
</qresource>
<qresource prefix="/smileys">
<file alias="angry">global/images/smileys/angry.png</file>
<file alias="confused">global/images/smileys/confused.png</file>
<file alias="cool">global/images/smileys/cool.png</file>
<file alias="cry">global/images/smileys/cry.png</file>
<file alias="evil">global/images/smileys/evil.png</file>
<file alias="happy">global/images/smileys/happy.png</file>
<file alias="heart">global/images/smileys/heart.png</file>
<file alias="indifference">global/images/smileys/indifference.png</file>
<file alias="kiss">global/images/smileys/kiss.png</file>
<file alias="laugh">global/images/smileys/laugh.png</file>
<file alias="laugh2">global/images/smileys/laugh2.png</file>
<file alias="nerdsmile">global/images/smileys/nerdsmile.png</file>
<file alias="quiet">global/images/smileys/quiet.png</file>
<file alias="sad">global/images/smileys/sad.png</file>
<file alias="skeptical">global/images/smileys/skeptical.png</file>
<file alias="smile">global/images/smileys/smile.png</file>
<file alias="suprised">global/images/smileys/suprised.png</file>
<file alias="tired">global/images/smileys/tired.png</file>
<file alias="tounge">global/images/smileys/tounge.png</file>
<file alias="wink">global/images/smileys/wink.png</file>
<file alias="wink2">global/images/smileys/wink2.png</file>
<file alias="wink3">global/images/smileys/wink3.png</file>
<file alias="fb/angel">global/images/smileys/fb/angel.png</file>
<file alias="fb/cry">global/images/smileys/fb/cry.png</file>
<file alias="fb/curlylips">global/images/smileys/fb/curlylips.png</file>
<file alias="fb/devil">global/images/smileys/fb/devil.png</file>
<file alias="fb/grumpy">global/images/smileys/fb/grumpy.png</file>
<file alias="fb/pacman">global/images/smileys/fb/pacman.png</file>
<file alias="fb/peng">global/images/smileys/fb/penguin.png</file>
<file alias="fb/poop">global/images/smileys/fb/poop.png</file>
<file alias="fb/putnam">global/images/smileys/fb/putnam.png</file>
<file alias="fb/robot">global/images/smileys/fb/robot.png</file>
<file alias="fb/shark">global/images/smileys/fb/shark.png</file>
<file alias="fb/thumb">global/images/smileys/fb/thumb.png</file>
<file alias="fb/unsure">global/images/smileys/fb/unshure.png</file>
<file alias="fb/upset">global/images/smileys/fb/upset.png</file>
<file alias="fb/kiki">global/images/smileys/fb/kiki.png</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion platforms/symbian/qml/Components/ChatDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Flickable {
MouseArea {
id: maAccItem
anchors { fill: parent }
onClicked: main.openChat(account,name,jid,chatType)
onClicked: main.openChat(account,name,jid,resource,chatType)
}

Connections {
Expand Down
2 changes: 1 addition & 1 deletion platforms/symbian/qml/Components/EventDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Flickable {
case 34: { xmppConnectivity.useClient(accountID).acceptSubscription(bareJid); dialog.createWithProperties("qrc:/dialogs/Contact/Add",{"accountId": accountID, "bareJid": bareJid}); xmppConnectivity.events.removeEvent(index); break; }
case 35: { dialog.createWithProperties("qrc:/dialogs/MUC/Join",{"accountId":accountID,"mucJid":bareJid}); xmppConnectivity.events.removeEvent(index)}; break;
case 38: if (updater.isUpdateAvailable) dialog.createWithProperties("qrc:/menus/UrlContext", {"url": updater.updateUrl}); break;
case 40: { if (!finished) xmppConnectivity.useClient(accountID).acceptTransfer(transferJob); else xmppConnectivity.useClient(accountID).openLocalTransferPath(transferJob)}; break;
case 40: { if (!finished) xmppConnectivity.useClient(accountID).acceptTransfer(transferJob,vars.receivedFilesPath); else xmppConnectivity.useClient(accountID).openLocalTransferPath(transferJob)}; break;
default: return false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions platforms/symbian/qml/Components/RosterItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ Item {
anchors { top: parent.top; topMargin: 4 }
sourceSize { width: platformStyle.graphicSizeMedium; height: platformStyle.graphicSizeMedium }
smooth: true
width: platformStyle.graphicSizeMedium; height: platformStyle.graphicSizeMedium
source: xmppConnectivity.getAvatarByJid(jid)
Rectangle { anchors.fill: parent; color: "black"; z: -1 }
Image {
anchors.fill: parent
sourceSize { width: platformStyle.graphicSizeMedium; height: platformStyle.graphicSizeMedium }
width: platformStyle.graphicSizeMedium; height: platformStyle.graphicSizeMedium
smooth: true
source: main.platformInverted ? "qrc:/avatar-mask_inverse" : "qrc:/avatar-mask"
}
Expand Down
2 changes: 1 addition & 1 deletion platforms/symbian/qml/Pages/ConversationPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Page {
Component.onCompleted: {
// sending a chat state meaning that chat is active if not in archive mode
if (!isInArchiveMode) {
xmppConnectivity.openChat( accountId,contactJid )
xmppConnectivity.openChat(accountId,contactJid,contactResource)
listViewMessages.model = xmppConnectivity.getMessages(contactJid)
} else {
archivePage = 1
Expand Down
13 changes: 8 additions & 5 deletions platforms/symbian/qml/Preflets/Connection.qml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ Item {
var recvFolder = avkon.openFolderSelectionDlg(settings.gStr("paths","recvFiles"));

settings.sStr(recvFolder,"paths","recvFiles")
if (recvFolder != "")
cacheDirText.text = "Currently used folder for received file is " + settings.gStr("paths","recvFiles")
else
recvDirText.text = "Not using custom folder for received files.";
vars.receivedFilesPath = recvFolder
recvDirText.updateText()
}
}

Expand All @@ -131,9 +129,14 @@ Item {
color: main.textColor
anchors { left: parent.left; right: parent.right }
font.pixelSize: platformStyle.fontSizeSmall
text: settings.gStr("paths","recvFiles") != "" ? "Currently used folder for received file is " + settings.gStr("paths","recvFiles") : "Not using custom folder for received files."
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignJustify

Component.onCompleted: updateText();

function updateText() {
text = vars.receivedFilesPath != "" ? "Currently used folder for received file is " + vars.receivedFilesPath : "Not using custom folder for received files."
}
}


Expand Down
7 changes: 5 additions & 2 deletions platforms/symbian/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ PageStackWindow {
}

}
function openChat(account,name,jid,type) {
pageStack.push("qrc:/pages/Conversation",{"accountId":account,"contactName":name,"contactJid":jid,"isInArchiveMode":false,"chatType":type})
function openChat(account,name,jid,resource,type) {
pageStack.push("qrc:/pages/Conversation",{"accountId":account,"contactName":name,"contactJid":jid,"contactResource":resource,"isInArchiveMode":false,"chatType":type})
}

Timer {
Expand Down Expand Up @@ -125,6 +125,9 @@ PageStackWindow {
xmppConnectivity.offlineContactsVisibility = !vars.hideOffline
avkon.setAppHiddenState(settings.gBool("behavior","hideFromTaskMgr"));

var recvFilesPath = settings.gStr("paths","recvFiles");
vars.receivedFilesPath = recvFilesPath == "false" ? "" : recvFilesPath

if (!settings.gBool("behavior","disableUpdateChecker"))
updater.checkForUpdate();

Expand Down
4 changes: 2 additions & 2 deletions src/database/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Settings::Settings(QObject *parent) : QSettings(Settings::confFile, QSettings::N
/*************************** (generic settings) **************************/
QVariant Settings::get(QString group, QString key) {
beginGroup( group );
QVariant ret = value( key, false );
QVariant ret = value(key,false);
endGroup();
return ret;
}
void Settings::set(QVariant data, QString group, QString key) {
void Settings::set(QVariant data, QString group, QString key) {
beginGroup(group);
setValue(key,data);
endGroup();
Expand Down
16 changes: 16 additions & 0 deletions src/models/ChatsItemModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ChatsItemModel : public ListItem
enum Roles {
roleAccount = Qt::UserRole+1,
roleName,
roleResource,
roleJid,
roleMsg,
roleType,
Expand All @@ -43,6 +44,7 @@ class ChatsItemModel : public ListItem
public:
ChatsItemModel(QObject *parent = 0): ListItem(parent) {
contactName = "";
contactResource = "";
contactJid = "";
contactAccountID = "";
chatMsg = "";
Expand All @@ -51,12 +53,14 @@ class ChatsItemModel : public ListItem
}
explicit ChatsItemModel( const QString &_contactName,
const QString &_contactJid,
const QString &_contactResource,
const QString _accountID,
const int _chatType,
QObject *parent = 0 ) : ListItem(parent),
contactAccountID(_accountID),
contactName(_contactName),
contactJid(_contactJid),
contactResource(_contactResource),
chatType(_chatType),
chatUnreadMsg(0)
{
Expand All @@ -68,6 +72,8 @@ class ChatsItemModel : public ListItem
return accountID();
case roleName:
return name();
case roleResource:
return resource();
case roleJid:
return jid();
case roleMsg:
Expand All @@ -84,6 +90,7 @@ class ChatsItemModel : public ListItem
QHash<int, QByteArray> names;
names[roleAccount] = "account";
names[roleName] = "name";
names[roleResource] = "resource";
names[roleJid] = "jid";
names[roleMsg] = "chatMsg";
names[roleType] = "chatType";
Expand All @@ -107,6 +114,13 @@ class ChatsItemModel : public ListItem
}
}

void setResource( const QString &_contactResource ) {
if(contactResource != _contactResource) {
contactResource = _contactResource;
emit dataChanged();
}
}

void setJid( const QString &_contactJid ) {
if(contactJid != _contactJid) {
contactJid = _contactJid;
Expand All @@ -126,6 +140,7 @@ class ChatsItemModel : public ListItem

inline QString accountID() const { return contactAccountID; }
inline QString name() const { return contactName; }
inline QString resource() const { return contactResource; }
inline QString jid() const { return contactJid; }
inline QString msg() const { return chatMsg; }
inline int type() const { return chatType; }
Expand All @@ -134,6 +149,7 @@ class ChatsItemModel : public ListItem
private:
QString contactAccountID;
QString contactName;
QString contactResource;
QString contactJid;
QString chatMsg;
int chatType;
Expand Down
35 changes: 30 additions & 5 deletions src/xmpp/MyXmppClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,23 @@ void MyXmppClient::forceRefreshVCard(QString bareJid) {
// ---------- handling messages (receiving/sending) ------------------------------------------------------------------------------

bool MyXmppClient::sendMessage(QString bareJid, QString resource, QString msgBody, int chatState, int msgType) {
if (xmppClient->state() != QXmppClient::ConnectedState)
if (xmppClient->state() != QXmppClient::ConnectedState || bareJid == "")
return false;

QString jid = bareJid;
if( resource == "" )
jid += "/resource";
else
jid += "/" + resource;

QXmppMessage xmppMsg;

if (msgType == QXmppMessage::GroupChat) {
QXmppMucRoom* room = mucRooms.value(bareJid);
return (room != NULL && room->isJoined()) ? room->sendMessage(msgBody) : false;
}

xmppMsg.setTo( bareJid + "/" + resource );
xmppMsg.setTo(jid);
xmppMsg.setFrom( m_myjid + "/" + xmppClient->configuration().resource() );

xmppMsg.setStamp(QDateTime::currentDateTime());
Expand Down Expand Up @@ -680,10 +686,29 @@ void MyXmppClient::sendAFile(QString bareJid, QString resource, QString path) {
events->appendTransferJob(m_accountId,job->jid(),contacts->getPropertyByJid(m_accountId,bareJid,"name"),description,jobId,false);
}

void MyXmppClient::acceptTransfer(int jobId) {
void MyXmppClient::acceptTransfer(int jobId, QString path) {
QXmppTransferJob* job = transferJobs.value(jobId);

QString recvPath = "";
QStringList defaultPaths = QStringList() << "F:/Received files/" << "E:/Received files/" << "C:/Data/Received files/" << "C:/Data/";

// check if path exists, if not, use something else
if (path == "" || path == "false" || !QFile::exists(path)) {
for (int i=0; i<defaultPaths.count(); i++) {
qDebug() << "trying path " << defaultPaths.at(i);
if (QFile::exists(defaultPaths.at(i))) {
recvPath = defaultPaths.at(i);
break;
}
}
} else { recvPath = path; }

qDebug() << recvPath;
if (recvPath == "") return;

if (job != NULL && job->state() == QXmppTransferJob::OfferState) {;
job->accept("F://Received files//" + job->fileName());
job->accept(recvPath + job->fileName());
qDebug() << "path is" << job->localFileUrl().toString();
events->updateTransferJob(m_accountId,job->jid(),"Transfer in progress... 0%\n"+job->fileName(),jobId,true,true);
}
}
Expand All @@ -699,7 +724,7 @@ void MyXmppClient::transferFinished() {
int jobId = transferJobs.key(job);
bool isIncoming = (job->direction() == QXmppTransferJob::IncomingDirection);
if (job->error() == QXmppTransferJob::NoError)
events->updateTransferJob(m_accountId,job->jid(),"Transfer finished. " + job->fileName(),jobId,isIncoming,true);
events->updateTransferJob(m_accountId,job->jid(),"Transfer finished. <b>Tap to open.</b> " + job->fileName(),jobId,isIncoming,true);
}

int MyXmppClient::fileTransferState(int jobId) {
Expand Down
2 changes: 1 addition & 1 deletion src/xmpp/MyXmppClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public :
}

// File transfer
Q_INVOKABLE void acceptTransfer(int jobId);
Q_INVOKABLE void acceptTransfer(int jobId, QString path);
Q_INVOKABLE void abortTransfer(int jobId);
Q_INVOKABLE int fileTransferState(int jobId);
Q_INVOKABLE void openLocalTransferPath(int jobId);
Expand Down
8 changes: 4 additions & 4 deletions src/xmpp/XmppConnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void XmppConnectivity::insertMessage(QString m_accountId,QString bareJid,QString
body = body.replace("<", "&lt;"); //and < stuff too ^^
body = msgWrapper->parseMsgOnLink(body);

this->openChat(m_accountId,bareJid);
this->openChat(m_accountId,bareJid,resource);

bool msgUnreadState;
if (type != 4 && mine == 0)
Expand Down Expand Up @@ -201,12 +201,12 @@ SqlQueryModel* XmppConnectivity::getSqlMessagesByPage(QString accountId, QString
}

// handling chats list
void XmppConnectivity::openChat(QString accountId, QString bareJid) {
void XmppConnectivity::openChat(QString accountId, QString bareJid, QString resource) {
if (!chats->checkIfExists(accountId + ";" + bareJid)) {
ChatsItemModel* chat;
QString message;
if (clients->value(accountId)->isMucRoom(bareJid)) {
chat = new ChatsItemModel(bareJid,bareJid,accountId,3);
chat = new ChatsItemModel(bareJid,bareJid,"",accountId,3);
chat->setUnreadMsg(0);
// change it to MUC room name one day
message = "[[INFO]] Joined chatroom\n[[bold]][[name]][[/bold]] @[[date]]";
Expand All @@ -215,7 +215,7 @@ void XmppConnectivity::openChat(QString accountId, QString bareJid) {
if (!contacts->doesContactExists(accountId,bareJid))
contacts->addContact(accountId,bareJid,bareJid);

chat = new ChatsItemModel(contacts->getPropertyByJid(accountId,bareJid,"name"),bareJid,accountId,0);
chat = new ChatsItemModel(contacts->getPropertyByJid(accountId,bareJid,"name"),bareJid,resource,accountId,0);
message = "[[INFO]] Chat started with [[bold]][[name]][[/bold]] @[[date]]";
}

Expand Down
2 changes: 1 addition & 1 deletion src/xmpp/XmppConnectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public slots:
Q_INVOKABLE QString getPropertyByJid(QString account,QString property,QString jid);
Q_INVOKABLE QString getPreservedMsg(QString accountId,QString jid);
Q_INVOKABLE void preserveMsg(QString accountId,QString jid,QString message);
Q_INVOKABLE void openChat(QString accountId, QString bareJid);
Q_INVOKABLE void openChat(QString accountId, QString bareJid, QString resource = "");
Q_INVOKABLE void closeChat(QString accountId, QString bareJid);
void updateChatName(QString m_accountId,QString bareJid,QString name);

Expand Down

0 comments on commit 394f479

Please sign in to comment.