Skip to content

Commit

Permalink
editor: add supports for GitHub and WeChat image hosting (vnotex#1007)
Browse files Browse the repository at this point in the history
* 增加了github imagebed的配置窗口

* 已经完成批量上传

* 基本上可以使用

* 基本上可以使用

* 加入进度条

* 就差开始的认证过程

* 差不多就这样了

* 修改中文的readme

* 修改了一下readme

* 找到不能传gif的问题所在

* 修改gif不能上传的bug

* 增加图床使用说明限制

* 增加一些注释

* 将进度条delete调

* 增加大文件上传错误提示

* 修复cancel的问题

* 已知问题: 上传多张图片时, 较大的图片的进度条不一定能出来

* 将进度条弹出来的时候修改成1s后

* 加入wechat设置, 改成QTabWidget

* wechat设置成功

* 成功获取了token

* 先保存一下, 文件上传有bug,替换好像也有bug

* 解决了boundary的引号导致图片不能上传的问题

* 注释掉一些输出

* 加入ip不在白名单的提示

* 增加图片大小大于1M的提示

* 将ip地址设置进剪切板, 并显示在弹框上

* 添加markdown转微信的url设置

* 增加自动打开openwrite的链接, 修复文件大小应为1024*1024

* 改成clear

* 将类型校验放到开始的地方

* 加入openwrite默认为空的判断

* Delete github-imagebed.md

* Apply suggestions from code review

Co-Authored-By: Le Tan <[email protected]>

* Apply suggestions from code review

Co-Authored-By: Le Tan <[email protected]>

* Apply suggestions from code review

Co-Authored-By: Le Tan <[email protected]>

* 根据要求修改了一下

* changed indentation and deleted empty line

* add some tr()

* Delete .DS_Store

* delete some comment and use CamelCase

* resolved sth
  • Loading branch information
fengwenhua authored and tamlok committed Nov 4, 2019
1 parent fccf686 commit c828ef0
Show file tree
Hide file tree
Showing 12 changed files with 1,104 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VNote.pro.user*
CMakeLists.txt.user
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Utilizing Qt, VNote could run on **Linux**, **Windows**, and **macOS**.
- Attachments of notes;
- Themes and dark mode;
- Rich and extensible export, such as HTML, PDF, PDF (All In One), and images;
- GitHub and WeChat image hosting;

# Donate
You could help VNote's development in many ways.
Expand Down
1 change: 1 addition & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ VNote 不是一个简单的 Markdown 编辑器。通过提供笔记管理功能
- 笔记附件;
- 主题以及深色模式;
- 丰富、可扩展的导出,包括 HTML、PDF、PDF(多合一)和图片;
- GitHub和微信图床;

# 捐赠
您可以通过很多途径帮助 VNote 的开发。
Expand Down
179 changes: 178 additions & 1 deletion src/dialog/vsettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ VSettingsDialog::VSettingsDialog(QWidget *p_parent)
addTab(new VNoteManagementTab(), tr("Note Management"));
addTab(new VMarkdownTab(), tr("Markdown"));
addTab(new VMiscTab(), tr("Misc"));
addTab(new VImageHostingTab(), tr("Image Hosting"));

m_tabList->setMaximumWidth(m_tabList->sizeHintForColumn(0) + 5);

Expand Down Expand Up @@ -206,6 +207,15 @@ void VSettingsDialog::loadConfiguration()
}
}

// ImageBed Tab
{
VImageHostingTab *imageBedTab = dynamic_cast<VImageHostingTab *>(m_tabs->widget(idx++));
Q_ASSERT(imageBedTab);
if (!imageBedTab->loadConfiguration()) {
goto err;
}
}

return;
err:
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
Expand Down Expand Up @@ -271,6 +281,15 @@ void VSettingsDialog::saveConfiguration()
}
}

// Image Hosting Tab.
{
VImageHostingTab *imageBedTab = dynamic_cast<VImageHostingTab *>(m_tabs->widget(idx++));
Q_ASSERT(imageBedTab);
if (!imageBedTab->saveConfiguration()) {
goto err;
}
}

accept();
return;
err:
Expand Down Expand Up @@ -1547,7 +1566,6 @@ bool VMiscTab::loadConfiguration()
if (!loadMatchesInPage()) {
return false;
}

return true;
}

Expand All @@ -1571,3 +1589,162 @@ bool VMiscTab::saveMatchesInPage()
g_config->setHighlightMatchesInPage(m_matchesInPageCB->isChecked());
return true;
}

VImageHostingTab::VImageHostingTab(QWidget *p_parent)
: QWidget(p_parent)
{
QTabWidget *imageHostingTabWeg = new QTabWidget(this);
QWidget *githubImageHostingTab = new QWidget();
QWidget *wechatImageHostingTab = new QWidget();
imageHostingTabWeg->addTab(githubImageHostingTab, tr("GitHub"));
imageHostingTabWeg->addTab(wechatImageHostingTab, tr("WeChat"));
imageHostingTabWeg->setCurrentIndex(0);

// Set the tab of GitHub image Hosting
m_personalAccessTokenEdit = new VLineEdit();
m_personalAccessTokenEdit->setToolTip(tr("GitHub personal access token"));
m_repoNameEdit = new VLineEdit();
m_repoNameEdit->setToolTip(tr("Name of GitHub repository for image hosting"));
m_userNameEdit = new VLineEdit();
m_userNameEdit->setToolTip(tr("User name of GitHub"));

QFormLayout *githubLayout = new QFormLayout();
githubLayout->addRow(tr("Personal access token:"), m_personalAccessTokenEdit);
githubLayout->addRow(tr("Repo name:"), m_repoNameEdit);
githubLayout->addRow(tr("User name:"), m_userNameEdit);

githubImageHostingTab->setLayout(githubLayout);

// Set the tab of GitHub image Hosting
m_appidEdit = new VLineEdit();
m_appidEdit->setToolTip(tr("WeChat appid"));
m_secretEdit = new VLineEdit();
m_secretEdit->setToolTip(tr("Please input wechat secret"));
m_markdown2WechatToolUrlEdit = new VLineEdit();
m_markdown2WechatToolUrlEdit->setToolTip(tr("Please input markdown to wechat tool's url"));

QFormLayout *wechatLayout = new QFormLayout();
wechatLayout->addRow(tr("appid:"), m_appidEdit);
wechatLayout->addRow(tr("secret:"), m_secretEdit);
wechatLayout->addRow(tr("markdown2WechatToolUrl"), m_markdown2WechatToolUrlEdit);

wechatImageHostingTab->setLayout(wechatLayout);
}

bool VImageHostingTab::loadAppid()
{
m_appidEdit->setText(g_config->getAppid());
return true;
}

bool VImageHostingTab::saveAppid()
{
g_config->setAppid(m_appidEdit->text());
return true;
}

bool VImageHostingTab::loadSecret()
{
m_secretEdit->setText(g_config->getSecret());
return true;
}

bool VImageHostingTab::saveSecret()
{
g_config->setSecret(m_secretEdit->text());
return true;
}

bool VImageHostingTab::loadMarkdown2WechatToolUrl()
{
m_markdown2WechatToolUrlEdit->setText(g_config->getMarkdown2WechatToolUrl());
return true;
}

bool VImageHostingTab::saveMarkdown2WechatToolUrl()
{
g_config->setMarkdown2WechatToolUrl(m_markdown2WechatToolUrlEdit->text());
return true;
}

bool VImageHostingTab::loadpersonalAccessToken()
{
m_personalAccessTokenEdit->setText(g_config->getpersonalAccessToken());
return true;
}

bool VImageHostingTab::savepersonalAccessToken()
{
g_config->setpersonalAccessToken(m_personalAccessTokenEdit->text());
return true;
}

bool VImageHostingTab::loadReposName()
{
m_repoNameEdit->setText(g_config->getReposName());
return true;
}

bool VImageHostingTab::saveReposName()
{
g_config->setReposName(m_repoNameEdit->text());
return true;
}

bool VImageHostingTab::loadUserName()
{
m_userNameEdit->setText(g_config->getUserName());
return true;
}

bool VImageHostingTab::saveUserName()
{
g_config->setUserName(m_userNameEdit->text());
return true;
}

bool VImageHostingTab::loadConfiguration()
{
if(!loadpersonalAccessToken()){
return false;
}
if(!loadReposName()){
return false;
}
if(!loadUserName()){
return false;
}
if(!loadAppid()){
return false;
}
if(!loadSecret()){
return false;
}
if(!loadMarkdown2WechatToolUrl()){
return false;
}
return true;
}

bool VImageHostingTab::saveConfiguration()
{
if(!savepersonalAccessToken()){
return false;
}
if(!saveReposName()){
return false;
}
if(!saveUserName()){
return false;
}
if(!saveAppid()){
return false;
}
if(!saveSecret()){
return false;
}
if(!saveMarkdown2WechatToolUrl()){
return false;
}
return true;
}
42 changes: 42 additions & 0 deletions src/dialog/vsettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QDialog>
#include <QVector>
#include <QString>
#include <QTabWidget>

class QDialogButtonBox;
class QComboBox;
Expand Down Expand Up @@ -270,6 +271,47 @@ class VMiscTab : public QWidget
QCheckBox *m_matchesInPageCB;
};

class VImageHostingTab : public QWidget
{
Q_OBJECT
public:
explicit VImageHostingTab(QWidget *p_parent = 0);
bool loadConfiguration();
bool saveConfiguration();

private:
bool loadpersonalAccessToken();
bool savepersonalAccessToken();

bool loadReposName();
bool saveReposName();

bool loadUserName();
bool saveUserName();

bool loadAppid();
bool saveAppid();

bool loadSecret();
bool saveSecret();

bool loadMarkdown2WechatToolUrl();
bool saveMarkdown2WechatToolUrl();

// personalAccessToken
VLineEdit *m_personalAccessTokenEdit;
// reposName
VLineEdit *m_repoNameEdit;
// userName
VLineEdit *m_userNameEdit;
// appid
VLineEdit *m_appidEdit;
// secret
VLineEdit *m_secretEdit;
// markdown to wechat tools url
VLineEdit *m_markdown2WechatToolUrlEdit;
};

class VSettingsDialog : public QDialog
{
Q_OBJECT
Expand Down
9 changes: 9 additions & 0 deletions src/resources/vnote.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[global]
; Wechat ImageBed
wechat_appid=
wechat_secret=
wechat_markdown_to_wechat_tool_url=
; Github ImageBed
github_personal_access_token=
github_repos_name=
github_user_name=

; Theme name
theme=v_pure

Expand Down
8 changes: 8 additions & 0 deletions src/vconfigmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ void VConfigManager::initialize()

initCodeBlockCssStyles();

m_personalAccessToken = getConfigFromSettings("global", "github_personal_access_token").toString();
m_reposName = getConfigFromSettings("global", "github_repos_name").toString();
m_userName = getConfigFromSettings("global", "github_user_name").toString();

m_appid = getConfigFromSettings("global", "wechat_appid").toString();
m_secret = getConfigFromSettings("global", "wechat_secret").toString();
m_markdown2WechatToolUrl = getConfigFromSettings("global", "wechat_markdown_to_wechat_tool_url").toString();

m_theme = getConfigFromSettings("global", "theme").toString();

m_editorStyle = getConfigFromSettings("global", "editor_style").toString();
Expand Down
Loading

0 comments on commit c828ef0

Please sign in to comment.