This commit is contained in:
Alex 2019-10-14 17:09:44 +00:00 committed by GitHub
commit 5218ff4e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 1407 additions and 1241 deletions

View File

@ -258,6 +258,7 @@ add_executable(Kepka WIN32 MACOSX_BUNDLE
SourceFiles/core/utils.cpp SourceFiles/core/utils.cpp
SourceFiles/data/data_abstract_structure.cpp SourceFiles/data/data_abstract_structure.cpp
SourceFiles/data/data_document.cpp
SourceFiles/data/data_drafts.cpp SourceFiles/data/data_drafts.cpp
SourceFiles/data/data_game.cpp SourceFiles/data/data_game.cpp
SourceFiles/data/data_photo.cpp SourceFiles/data/data_photo.cpp

View File

@ -30,7 +30,6 @@
#include "mtproto/core_types.h" #include "mtproto/core_types.h"
#include "mtproto/rpc_sender.h" #include "mtproto/rpc_sender.h"
#include "mtproto/sender.h" #include "mtproto/sender.h"
#include "structs.h"
#include <QtCore/QObject> #include <QtCore/QObject>
class AuthSession; class AuthSession;

View File

@ -23,7 +23,7 @@
#pragma once #pragma once
#include "base/timer.h" #include "base/timer.h"
#include "structs.h" #include "data/data_peer.h"
namespace Storage { namespace Storage {
class Downloader; class Downloader;

View File

@ -25,8 +25,8 @@
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "core/basic_types.h" #include "core/basic_types.h"
#include "data/data_types.h" #include "data/data_types.h"
#include "data/data_peer.h"
#include "structs.h" // temporarily. (ChannelData
namespace Ui { namespace Ui {
class FlatLabel; class FlatLabel;

View File

@ -23,7 +23,7 @@
#pragma once #pragma once
#include "base/observer.h" #include "base/observer.h"
#include "structs.h" #include "data/data_peer.h" // BotCommand
#include "ui/animation.h" #include "ui/animation.h"
#include "ui/twidget.h" #include "ui/twidget.h"
#include <QTimer> #include <QTimer>

View File

@ -0,0 +1,37 @@
//
// This file is part of Kepka,
// an unofficial desktop version of Telegram messaging app,
// see https://github.com/procxx/kepka
//
// Kepka is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// It 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 General Public License for more details.
//
// In addition, as a special exception, the copyright holders give permission
// to link the code of portions of this program with the OpenSSL library.
//
// Full license: https://github.com/procxx/kepka/blob/master/LICENSE
// Copyright (c) 2019- Kepka Contributors, https://github.com/procxx
//
/// @file data/data_document.cpp Implementation and internals (and Qt QFixed)
/// @todo Get rid of QFixed.
#include "data/data_document.h"
#include "private/qfixed_p.h"
#include <QTextEdit>
void MessageCursor::fillFrom(const QTextEdit *edit) {
QTextCursor c = edit->textCursor();
position = c.position();
anchor = c.anchor();
QScrollBar *s = edit->verticalScrollBar();
scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX;
}
const int MessageCursor::kMaxScroll = QFIXED_MAX;

View File

@ -24,15 +24,21 @@
#pragma once #pragma once
#include <QByteArray> #include <QByteArray>
#include <QScrollBar>
#include <QString> #include <QString>
#include <QSize> #include <QSize>
#include <QTextEdit>
#include <QVector> #include <QVector>
#include "core/click_handler.h" // LeftButtonClickHandler
#include "data/data_types.h" #include "data/data_types.h"
#include "data/data_photo.h" // PhotoData
#include "ui/images.h" // StorageKey, ImagePtr, StorageImageLocation #include "ui/images.h" // StorageKey, ImagePtr, StorageImageLocation
#include "scheme.h" #include "scheme.h"
class QTextEdit;
class HistoryItem; class HistoryItem;
enum LocationType { enum LocationType {
@ -322,3 +328,224 @@ private:
void destroyLoaderDelayed(mtpFileLoader *newValue = nullptr) const; void destroyLoaderDelayed(mtpFileLoader *newValue = nullptr) const;
}; };
static const WebPageId CancelledWebPageId = 0xFFFFFFFFFFFFFFFFULL;
inline bool operator==(const FullMsgId &a, const FullMsgId &b) {
return (a.channel == b.channel) && (a.msg == b.msg);
}
inline bool operator!=(const FullMsgId &a, const FullMsgId &b) {
return !(a == b);
}
inline bool operator<(const FullMsgId &a, const FullMsgId &b) {
if (a.msg < b.msg) return true;
if (a.msg > b.msg) return false;
return a.channel < b.channel;
}
inline constexpr bool isClientMsgId(MsgId id) {
return id >= StartClientMsgId && id < EndClientMsgId;
}
class UserData;
class ChatData;
class ChannelData;
typedef QMap<char, QPixmap> PreparedPhotoThumbs;
bool fileIsImage(const QString &name, const QString &mime);
namespace Serialize {
class Document;
} // namespace Serialize
class AudioMsgId {
public:
enum class Type {
Unknown,
Voice,
Song,
Video,
};
AudioMsgId() = default;
AudioMsgId(DocumentData *audio, const FullMsgId &msgId, quint32 playId = 0)
: _audio(audio)
, _contextId(msgId)
, _playId(playId) {
setTypeFromAudio();
}
Type type() const {
return _type;
}
DocumentData *audio() const {
return _audio;
}
FullMsgId contextId() const {
return _contextId;
}
quint32 playId() const {
return _playId;
}
explicit operator bool() const {
return _audio != nullptr;
}
private:
void setTypeFromAudio() {
if (_audio->voice() || _audio->isRoundVideo()) {
_type = Type::Voice;
} else if (_audio->isVideo()) {
_type = Type::Video;
} else if (_audio->tryPlaySong()) {
_type = Type::Song;
} else {
_type = Type::Unknown;
}
}
DocumentData *_audio = nullptr;
Type _type = Type::Unknown;
FullMsgId _contextId;
quint32 _playId = 0;
};
inline bool operator<(const AudioMsgId &a, const AudioMsgId &b) {
if (quintptr(a.audio()) < quintptr(b.audio())) {
return true;
} else if (quintptr(b.audio()) < quintptr(a.audio())) {
return false;
} else if (a.contextId() < b.contextId()) {
return true;
} else if (b.contextId() < a.contextId()) {
return false;
}
return (a.playId() < b.playId());
}
inline bool operator==(const AudioMsgId &a, const AudioMsgId &b) {
return a.audio() == b.audio() && a.contextId() == b.contextId() && a.playId() == b.playId();
}
inline bool operator!=(const AudioMsgId &a, const AudioMsgId &b) {
return !(a == b);
}
class DocumentClickHandler : public LeftButtonClickHandler {
public:
DocumentClickHandler(DocumentData *document)
: _document(document) {}
DocumentData *document() const {
return _document;
}
private:
DocumentData *_document;
};
class DocumentSaveClickHandler : public DocumentClickHandler {
public:
using DocumentClickHandler::DocumentClickHandler;
static void doSave(DocumentData *document, bool forceSavingAs = false);
protected:
void onClickImpl() const override;
};
class DocumentOpenClickHandler : public DocumentClickHandler {
public:
using DocumentClickHandler::DocumentClickHandler;
static void doOpen(DocumentData *document, HistoryItem *context, ActionOnLoad action = ActionOnLoadOpen);
protected:
void onClickImpl() const override;
};
class GifOpenClickHandler : public DocumentOpenClickHandler {
public:
using DocumentOpenClickHandler::DocumentOpenClickHandler;
protected:
void onClickImpl() const override;
};
class VoiceSeekClickHandler : public DocumentOpenClickHandler {
public:
using DocumentOpenClickHandler::DocumentOpenClickHandler;
protected:
void onClickImpl() const override {}
};
class DocumentCancelClickHandler : public DocumentClickHandler {
public:
using DocumentClickHandler::DocumentClickHandler;
protected:
void onClickImpl() const override;
};
enum WebPageType { WebPagePhoto, WebPageVideo, WebPageProfile, WebPageArticle };
inline WebPageType toWebPageType(const QString &type) {
if (type == qstr("photo")) return WebPagePhoto;
if (type == qstr("video")) return WebPageVideo;
if (type == qstr("profile")) return WebPageProfile;
return WebPageArticle;
}
struct WebPageData {
WebPageData(const WebPageId &id, WebPageType type = WebPageArticle, const QString &url = QString(),
const QString &displayUrl = QString(), const QString &siteName = QString(),
const QString &title = QString(), const TextWithEntities &description = TextWithEntities(),
DocumentData *doc = nullptr, PhotoData *photo = nullptr, qint32 duration = 0,
const QString &author = QString(), qint32 pendingTill = -1);
void forget() {
if (document) document->forget();
if (photo) photo->forget();
}
WebPageId id;
WebPageType type;
QString url, displayUrl, siteName, title;
TextWithEntities description;
qint32 duration;
QString author;
PhotoData *photo;
DocumentData *document;
qint32 pendingTill;
};
QString saveFileName(const QString &title, const QString &filter, const QString &prefix, QString name, bool savingAs,
const QDir &dir = QDir());
MsgId clientMsgId();
struct MessageCursor {
static const int kMaxScroll;
MessageCursor() = default;
MessageCursor(int position, int anchor, int scroll)
: position(position)
, anchor(anchor)
, scroll(scroll) {}
MessageCursor(const QTextEdit *edit) {
fillFrom(edit);
}
void fillFrom(const QTextEdit *edit);
void applyTo(QTextEdit *edit) {
auto cursor = edit->textCursor();
cursor.setPosition(anchor, QTextCursor::MoveAnchor);
cursor.setPosition(position, QTextCursor::KeepAnchor);
edit->setTextCursor(cursor);
if (auto scrollbar = edit->verticalScrollBar()) {
scrollbar->setValue(scroll);
}
}
int position = 0;
int anchor = 0;
int scroll = kMaxScroll;
};
inline bool operator==(const MessageCursor &a, const MessageCursor &b) {
return (a.position == b.position) && (a.anchor == b.anchor) && (a.scroll == b.scroll);
}

View File

@ -0,0 +1,88 @@
//
// This file is part of Kepka,
// an unofficial desktop version of Telegram messaging app,
// see https://github.com/procxx/kepka
//
// Kepka is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// It 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 General Public License for more details.
//
// In addition, as a special exception, the copyright holders give permission
// to link the code of portions of this program with the OpenSSL library.
//
// Full license: https://github.com/procxx/kepka/blob/master/LICENSE
// Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
// Copyright (c) 2017- Kepka Contributors, https://github.com/procxx
//
#pragma once
namespace Data {
template <
typename FlagsType,
typename FlagsType::Type kEssential = -1>
class Flags {
public:
struct Change {
Change(FlagsType diff, FlagsType value)
: diff(diff)
, value(value) {
}
FlagsType diff = 0;
FlagsType value = 0;
};
Flags() = default;
Flags(FlagsType value) : _value(value) {
}
void set(FlagsType which) {
if (auto diff = which ^ _value) {
_value = which;
//updated(diff);
}
}
void add(FlagsType which) {
if (auto diff = which & ~_value) {
_value |= which;
//updated(diff);
}
}
void remove(FlagsType which) {
if (auto diff = which & _value) {
_value &= ~which;
//updated(diff);
}
}
FlagsType current() const {
return _value;
}
// rpl::producer<Change> changes() const {
// return _changes.events();
// }
// rpl::producer<Change> value() const {
// return _changes.events_starting_with({
// FlagsType::from_raw(kEssential),
// _value });
// }
private:
// void updated(FlagsType diff) {
// if ((diff &= FlagsType::from_raw(kEssential))) {
// _changes.fire({ diff, _value });
// }
// }
FlagsType _value = 0;
//rpl::event_stream<Change> _changes;
};
} // namespace Data

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@
#include <QPair> #include <QPair>
#include "core/utils.h" // TimeMs and stuff #include "core/utils.h" // TimeMs and stuff
using PhotoId = quint64;
using VideoId = quint64; using VideoId = quint64;
using AudioId = quint64; using AudioId = quint64;
using DocumentId = quint64; using DocumentId = quint64;

View File

@ -24,7 +24,7 @@
#include "dialogs/dialogs_common.h" #include "dialogs/dialogs_common.h"
#include "dialogs/dialogs_list.h" #include "dialogs/dialogs_list.h"
#include "structs.h" #include "data/data_peer.h" // PeerData and inner
class History; class History;

View File

@ -29,9 +29,9 @@
#include "ui/animation.h" // For BasicAnimation #include "ui/animation.h" // For BasicAnimation
#include "ui/effects/send_action_animations.h" // For SendActionAnimation #include "ui/effects/send_action_animations.h" // For SendActionAnimation
#include "ui/text/text.h" #include "ui/text/text.h"
#include "data/data_peer.h"
#include "data/data_photo.h" #include "data/data_photo.h"
#include "data/data_game.h" #include "data/data_game.h"
#include "structs.h"
void HistoryInit(); void HistoryInit();

View File

@ -22,6 +22,7 @@
// //
#pragma once #pragma once
#include "data/data_document.h"
#include "history/history_media.h" #include "history/history_media.h"
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"

View File

@ -24,9 +24,9 @@
#include "base/flags.h" #include "base/flags.h"
#include "base/observer.h" #include "base/observer.h"
#include "data/data_document.h"
#include "history/history.h" #include "history/history.h"
#include "structs.h"
namespace Notify { namespace Notify {

View File

@ -24,8 +24,8 @@
#include "QTimer" #include "QTimer"
#include "core/click_handler.h" #include "core/click_handler.h"
#include "data/data_peer.h" // PeerData, UserData
#include "profile/profile_block_peer_list.h" #include "profile/profile_block_peer_list.h"
#include "structs.h"
class UserData; class UserData;
class ChannelData; class ChannelData;

View File

@ -22,7 +22,7 @@
// //
#pragma once #pragma once
#include "structs.h" #include "data/data_peer.h" // PeerData, UserData
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
#include "ui/text/text.h" #include "ui/text/text.h"
#include "window/section_memento.h" #include "window/section_memento.h"

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,7 @@
#include "base/flags.h" #include "base/flags.h"
#include "core/click_handler.h" #include "core/click_handler.h"
#include "private/qfixed_p.h" #include "private/qfixed_p.h" // QFixed
#include "styles/style_basic.h" #include "styles/style_basic.h"
#include "ui/emoji_config.h" #include "ui/emoji_config.h"
#include "ui/text/text_entity.h" #include "ui/text/text_entity.h"

View File

@ -23,6 +23,7 @@
#include "window/notifications_utilities.h" #include "window/notifications_utilities.h"
#include "messenger.h" #include "messenger.h"
#include "data/data_peer.h"
#include "platform/platform_specific.h" #include "platform/platform_specific.h"
#include "styles/style_window.h" #include "styles/style_window.h"