summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-12 18:18:57 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-12 18:18:57 +0300
commit08840edfd4acce464d32244b5ccc3648588ce33d (patch)
tree61c799d10e287bf8ae1e293edee75ea5615328b2
parentd0516970abbb1c4ae87ae31e360214b5e7e7763f (diff)
first attempt to make offline transfers visible
-rw-r--r--include/m_database.h5
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp35
-rw-r--r--plugins/Dbx_sqlite/src/dbintf.h3
-rw-r--r--protocols/JabberG/src/jabber_file.cpp25
-rw-r--r--src/core/stdmsg/src/msglog.cpp44
-rw-r--r--src/mir_app/src/mir_app.def4
-rw-r--r--src/mir_app/src/mir_app64.def5
7 files changed, 91 insertions, 30 deletions
diff --git a/include/m_database.h b/include/m_database.h
index c29f589495..31b232ca90 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -720,10 +720,11 @@ namespace DB
__forceinline const wchar_t* getName() const { return m_wszFileName; }
__forceinline const wchar_t* getDescr() const { return m_wszDescription; }
+ __forceinline uint32_t getSize() const { return m_iFileSize; }
+ __forceinline uint32_t getTransferred() const { return m_iTransferred; }
+
__forceinline bool isCompleted() const { return m_iFileSize == 0 || m_iFileSize == m_iTransferred; }
__forceinline bool isOffline() const { return m_szProtoString != nullptr; }
-
- __forceinline void setSize(uint32_t iSize) { m_iFileSize = m_iTransferred = iSize; }
};
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index bc8ab23c78..6e91e33f98 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -295,6 +295,41 @@ BOOL CDbxSQLite::EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbei)
return 0;
}
+int CDbxSQLite::SetEventJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv)
+{
+ if (hDbEvent == 0)
+ return 1;
+
+ { mir_cslock lock(m_csDbAccess);
+ sqlite3_stmt *stmt = InitQuery("UPDATE events SET body=json_set(body, '$.?', ?) WHERE id = ?;", qEvEdit);
+ sqlite3_bind_text(stmt, 1, szSetting, (int)mir_strlen(szSetting), nullptr);
+ switch (dbv->type) {
+ case DBVT_BYTE:
+ sqlite3_bind_int(stmt, 2, dbv->bVal);
+ break;
+ case DBVT_WORD:
+ sqlite3_bind_int(stmt, 2, dbv->wVal);
+ break;
+ case DBVT_DWORD:
+ sqlite3_bind_int(stmt, 2, dbv->dVal);
+ break;
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ sqlite3_bind_text(stmt, 2, dbv->pszVal, (int)mir_strlen(dbv->pszVal), nullptr);
+ break;
+ default:
+ return 2;
+ }
+ sqlite3_bind_int64(stmt, 3, hDbEvent);
+ int rc = sqlite3_step(stmt);
+ logError(rc, __FILE__, __LINE__);
+ sqlite3_reset(stmt);
+ }
+
+ DBFlush();
+ return 0;
+}
+
int CDbxSQLite::GetBlobSize(MEVENT hDbEvent)
{
if (hDbEvent == 0)
diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h
index 6712570cf9..83071ae90c 100644
--- a/plugins/Dbx_sqlite/src/dbintf.h
+++ b/plugins/Dbx_sqlite/src/dbintf.h
@@ -94,7 +94,7 @@ class CDbxSQLite : public MDatabaseCommon, public MIDatabaseChecker, public MZer
void UninitEvents();
CQuery qEvCount, qEvAdd, qEvDel, qEvEdit, qEvBlobSize, qEvGet, qEvGetFlags, qEvSetFlags, qEvGetContact, qEvGetContact2;
CQuery qEvFindFirst, qEvFindNext, qEvFindLast, qEvFindPrev, qEvFindUnread, qEvAddSrt, qEvDelSrt, qEvMetaSplit, qEvMetaMerge;
- CQuery qEvGetById, qEvUpdateId;
+ CQuery qEvGetById, qEvUpdateId, qEvSetJson;
int DeleteEventMain(MEVENT);
int DeleteEventSrt(MEVENT, MCONTACT, uint32_t);
@@ -127,6 +127,7 @@ public:
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT contactID, const DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) DeleteEvent(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbe) override;
+ STDMETHODIMP_(int) SetEventJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *dbv) override;
STDMETHODIMP_(int) GetBlobSize(MEVENT hDbEvent) override;
STDMETHODIMP_(BOOL) GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbe) override;
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) override;
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index 24ea2c6296..c96f6ae92c 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -46,19 +46,18 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *param)
// download the page
NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
- if (nlhrReply) {
- if (nlhrReply->resultCode == 200) {
- FILE *f = _wfopen(param->wszPath, L"wb");
- fwrite(nlhrReply->pData, 1, nlhrReply->dataLength, f);
- fclose(f);
-
- blob.setSize(nlhrReply->dataLength);
- blob.write(dbei);
- db_event_edit(param->hDbEvent, &dbei);
-
- if (param->bOpen)
- ShellExecute(nullptr, L"open", param->wszPath, nullptr, nullptr, SW_SHOWDEFAULT);
- }
+ if (nlhrReply && nlhrReply->resultCode == 200) {
+ FILE *f = _wfopen(param->wszPath, L"wb");
+ fwrite(nlhrReply->pData, 1, nlhrReply->dataLength, f);
+ fclose(f);
+
+ DBVARIANT dbv = { DBVT_DWORD };
+ dbv.dVal = nlhrReply->dataLength;
+ db_event_setJson(param->hDbEvent, "ft", &dbv);
+ db_event_setJson(param->hDbEvent, "fs", &dbv);
+
+ if (param->bOpen)
+ ShellExecute(nullptr, L"open", param->wszPath, nullptr, nullptr, SW_SHOWDEFAULT);
}
}
}
diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp
index a105a2fe53..778ae5f991 100644
--- a/src/core/stdmsg/src/msglog.cpp
+++ b/src/core/stdmsg/src/msglog.cpp
@@ -195,7 +195,7 @@ bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei)
bool DbEventIsShown(const DBEVENTINFO *dbei)
{
- return (dbei->eventType == EVENTTYPE_MESSAGE) || DbEventIsForMsgWindow(dbei);
+ return dbei->eventType == EVENTTYPE_MESSAGE || dbei->eventType == EVENTTYPE_FILE || DbEventIsForMsgWindow(dbei);
}
static bool CreateRTFFromDbEvent(LogStreamData *dat)
@@ -303,18 +303,40 @@ static bool CreateRTFFromDbEvent(LogStreamData *dat)
break;
case EVENTTYPE_FILE:
+ SetToStyle(MSGFONTID_NOTICE, buf);
{
DB::FILE_BLOB blob(dbei);
-
- SetToStyle(MSGFONTID_NOTICE, buf);
- AppendToBufferWithRTF(buf, (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received"));
- buf.Append(": ");
- AppendToBufferWithRTF(buf, blob.getName());
-
- if (*blob.getDescr() != 0) {
- buf.Append(" (");
- AppendToBufferWithRTF(buf, blob.getDescr());
- buf.Append(")");
+ if (blob.isOffline()) {
+ AppendToBufferWithRTF(buf, TranslateT("Offline file"));
+ buf.Append(" {\\field{\\*\\fldinst HYPERLINK \"");
+ buf.AppendFormat("ofile:%ul", dat->hDbEvent);
+ buf.Append("\"}{\\fldrslt{\\ul ");
+ AppendToBufferWithRTF(buf, blob.getName());
+ buf.AppendFormat("}}} | %uKB", blob.getSize() / 1024);
+
+ CMStringA szHost;
+ if (const char *b = strstr(blob.getUrl(), "://"))
+ for (b = b + 3; *b != 0 && *b != '/' && *b != ':'; b++)
+ szHost.AppendChar(*b);
+
+ if (!szHost.IsEmpty())
+ buf.AppendFormat(" on %s", szHost.c_str());
+
+ if (blob.getSize() > 0 && blob.getSize() == blob.getTransferred()) {
+ buf.AppendChar(' ');
+ AppendToBufferWithRTF(buf, TranslateT("Completed"));
+ }
+ }
+ else {
+ AppendToBufferWithRTF(buf, (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received"));
+ buf.Append(": ");
+ AppendToBufferWithRTF(buf, blob.getName());
+
+ if (*blob.getDescr() != 0) {
+ buf.Append(" (");
+ AppendToBufferWithRTF(buf, blob.getDescr());
+ buf.Append(")");
+ }
}
}
break;
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index f4c74509a7..c1d9a5682b 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -846,4 +846,6 @@ Chat_IsMuted @941 NONAME
?getUrl@FILE_BLOB@DB@@QBEPBDXZ @961 NONAME
?isCompleted@FILE_BLOB@DB@@QBE_NXZ @962 NONAME
?isOffline@FILE_BLOB@DB@@QBE_NXZ @963 NONAME
-?setSize@FILE_BLOB@DB@@QAEXI@Z @964 NONAME
+?SetEventJson@MDatabaseCommon@@UAGHIPBDPAUDBVARIANT@@@Z @964 NONAME
+?getSize@FILE_BLOB@DB@@QBEIXZ @965 NONAME
+?getTransferred@FILE_BLOB@DB@@QBEIXZ @966 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index a6e78bcdad..1ad0ea4d87 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -846,5 +846,6 @@ Chat_IsMuted @941 NONAME
?getUrl@FILE_BLOB@DB@@QEBAPEBDXZ @961 NONAME
?isCompleted@FILE_BLOB@DB@@QEBA_NXZ @962 NONAME
?isOffline@FILE_BLOB@DB@@QEBA_NXZ @963 NONAME
-?setSize@FILE_BLOB@DB@@QEAAXI@Z @964 NONAME
-?SetEventJson@MDatabaseCommon@@UEAAHIPEBDPEAUDBVARIANT@@@Z @965 NONAME
+?SetEventJson@MDatabaseCommon@@UEAAHIPEBDPEAUDBVARIANT@@@Z @964 NONAME
+?getSize@FILE_BLOB@DB@@QEBAIXZ @965 NONAME
+?getTransferred@FILE_BLOB@DB@@QEBAIXZ @966 NONAME