Skip to content

Commit

Permalink
Add basic HTML export.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 24, 2018
1 parent e708065 commit 9d66f9c
Show file tree
Hide file tree
Showing 22 changed files with 1,903 additions and 65 deletions.
3 changes: 3 additions & 0 deletions Telegram/Resources/css/export_style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.page_wrap {
background-color: #fff;
}
2 changes: 1 addition & 1 deletion Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_export_option_size_limit" = "Size limit: {size}";
"lng_export_header_format" = "Location and format";
"lng_export_option_location" = "Download path: {path}";
"lng_export_option_text" = "Human-readable text";
"lng_export_option_html" = "Human-readable HTML";
"lng_export_option_json" = "Machine-readable JSON";
"lng_export_start" = "Export";
"lng_export_state_initializing" = "Initializing...";
Expand Down
3 changes: 3 additions & 0 deletions Telegram/Resources/qrc/telegram.qrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<RCC>
<qresource prefix="/export">
<file alias="css/style.css">../css/export_style.css</file>
</qresource>
<qresource prefix="/gui">
<file alias="fonts/OpenSans-Regular.ttf">../fonts/OpenSans-Regular.ttf</file>
<file alias="fonts/OpenSans-Bold.ttf">../fonts/OpenSans-Bold.ttf</file>
Expand Down
29 changes: 21 additions & 8 deletions Telegram/SourceFiles/export/data/export_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ User ParseUser(const MTPUser &data) {
if (data.has_bot_info_version()) {
result.isBot = true;
}
if (data.is_self()) {
result.isSelf = true;
}
const auto access_hash = data.has_access_hash()
? data.vaccess_hash
: MTP_long(0);
Expand Down Expand Up @@ -492,7 +495,8 @@ Chat ParseChat(const MTPChat &data) {
result.input = MTP_inputPeerChat(MTP_int(result.id));
}, [&](const MTPDchannel &data) {
result.id = data.vid.v;
result.broadcast = data.is_broadcast();
result.isBroadcast = data.is_broadcast();
result.isSupergroup = data.is_megagroup();
result.title = ParseString(data.vtitle);
if (data.has_username()) {
result.username = ParseString(data.vusername);
Expand All @@ -502,7 +506,8 @@ Chat ParseChat(const MTPChat &data) {
data.vaccess_hash);
}, [&](const MTPDchannelForbidden &data) {
result.id = data.vid.v;
result.broadcast = data.is_broadcast();
result.isBroadcast = data.is_broadcast();
result.isSupergroup = data.is_megagroup();
result.title = ParseString(data.vtitle);
result.input = MTP_inputPeerChannel(
MTP_int(result.id),
Expand Down Expand Up @@ -1102,16 +1107,22 @@ SessionsList ParseWebSessionsList(
DialogInfo::Type DialogTypeFromChat(const Chat &chat) {
using Type = DialogInfo::Type;
return chat.username.isEmpty()
? (chat.broadcast
? (chat.isBroadcast
? Type::PrivateChannel
: chat.isSupergroup
? Type::PrivateSupergroup
: Type::PrivateGroup)
: (chat.broadcast
: (chat.isBroadcast
? Type::PublicChannel
: Type::PublicGroup);
: Type::PublicSupergroup);
}

DialogInfo::Type DialogTypeFromUser(const User &user) {
return user.isBot ? DialogInfo::Type::Bot : DialogInfo::Type::Personal;
return user.isSelf
? DialogInfo::Type::Self
: user.isBot
? DialogInfo::Type::Bot
: DialogInfo::Type::Personal;
}

DialogsInfo ParseDialogsInfo(const MTPmessages_Dialogs &data) {
Expand Down Expand Up @@ -1185,11 +1196,13 @@ void FinalizeDialogsInfo(DialogsInfo &info, const Settings &settings) {
using Type = Settings::Type;
const auto setting = [&] {
switch (dialog.type) {
case DialogType::Self:
case DialogType::Personal: return Type::PersonalChats;
case DialogType::Bot: return Type::BotChats;
case DialogType::PrivateGroup: return Type::PrivateGroups;
case DialogType::PrivateGroup:
case DialogType::PrivateSupergroup: return Type::PrivateGroups;
case DialogType::PrivateChannel: return Type::PrivateChannels;
case DialogType::PublicGroup: return Type::PublicGroups;
case DialogType::PublicSupergroup: return Type::PublicGroups;
case DialogType::PublicChannel: return Type::PublicChannels;
}
Unexpected("Type in ApiWrap::onlyMyMessages.");
Expand Down
10 changes: 7 additions & 3 deletions Telegram/SourceFiles/export/data/export_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ struct User {
ContactInfo info;
Utf8String username;
bool isBot = false;
bool isSelf = false;

MTPInputUser input = MTP_inputUserEmpty();

Expand All @@ -175,7 +176,8 @@ struct Chat {
int32 id = 0;
Utf8String title;
Utf8String username;
bool broadcast = false;
bool isBroadcast = false;
bool isSupergroup = false;

MTPInputPeer input = MTP_inputPeerEmpty();
};
Expand Down Expand Up @@ -466,10 +468,12 @@ std::map<uint64, Message> ParseMessagesList(
struct DialogInfo {
enum class Type {
Unknown,
Self,
Personal,
Bot,
PrivateGroup,
PublicGroup,
PrivateSupergroup,
PublicSupergroup,
PrivateChannel,
PublicChannel,
};
Expand All @@ -479,7 +483,7 @@ struct DialogInfo {
MTPInputPeer input = MTP_inputPeerEmpty();
int32 topMessageId = 0;
TimeId topMessageDate = 0;
PeerId peerId = 0;
PeerId peerId;

// User messages splits which contained that dialog.
std::vector<int> splits;
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/export/export_api_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ LocationKey ComputeLocationKey(const Data::FileLocation &value) {
Settings::Type SettingsFromDialogsType(Data::DialogInfo::Type type) {
using DialogType = Data::DialogInfo::Type;
switch (type) {
case DialogType::Self:
case DialogType::Personal:
return Settings::Type::PersonalChats;
case DialogType::Bot:
return Settings::Type::BotChats;
case DialogType::PrivateGroup:
case DialogType::PrivateSupergroup:
return Settings::Type::PrivateGroups;
case DialogType::PublicGroup:
case DialogType::PublicSupergroup:
return Settings::Type::PublicGroups;
case DialogType::PrivateChannel:
return Settings::Type::PrivateChannels;
Expand Down
33 changes: 1 addition & 32 deletions Telegram/SourceFiles/export/export_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,43 +223,12 @@ void Controller::startExport(const Settings &settings) {
}
_settings = base::duplicate(settings);

if (!normalizePath()) {
ioError(_settings.path);
return;
}
_settings.path = Output::NormalizePath(_settings.path);
_writer = Output::CreateWriter(_settings.format);
fillExportSteps();
exportNext();
}

bool Controller::normalizePath() {
QDir folder(_settings.path);
const auto path = folder.absolutePath();
_settings.path = path.endsWith('/') ? path : (path + '/');
if (!folder.exists()) {
return true;
}
const auto mode = QDir::AllEntries | QDir::NoDotAndDotDot;
const auto list = folder.entryInfoList(mode);
if (list.isEmpty()) {
return true;
}
const auto date = QDate::currentDate();
const auto base = QString("DataExport_%1_%2_%3"
).arg(date.day(), 2, 10, QChar('0')
).arg(date.month(), 2, 10, QChar('0')
).arg(date.year());
const auto add = [&](int i) {
return base + (i ? " (" + QString::number(i) + ')' : QString());
};
auto index = 0;
while (QDir(_settings.path + add(index)).exists()) {
++index;
}
_settings.path += add(index) + '/';
return true;
}

void Controller::fillExportSteps() {
using Type = Settings::Type;
_steps.push_back(Step::Initializing);
Expand Down
Loading

0 comments on commit 9d66f9c

Please sign in to comment.