From 7a8e3055b162b2572152ed951ebcefd60182edbc Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Mon, 23 Jul 2012 12:21:37 +0000 Subject: PasteIt, PopUp, ProfileManager: changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1117 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PasteIt/src/Options.cpp | 979 ++++++++++++++++++++++++++++++++++++ plugins/PasteIt/src/Options.h | 72 +++ plugins/PasteIt/src/PasteIt.cpp | 564 +++++++++++++++++++++ plugins/PasteIt/src/PasteToWeb.cpp | 577 +++++++++++++++++++++ plugins/PasteIt/src/PasteToWeb.h | 47 ++ plugins/PasteIt/src/PasteToWeb1.cpp | 393 +++++++++++++++ plugins/PasteIt/src/PasteToWeb1.h | 40 ++ plugins/PasteIt/src/PasteToWeb2.cpp | 247 +++++++++ plugins/PasteIt/src/PasteToWeb2.h | 38 ++ plugins/PasteIt/src/resource.h | 50 ++ plugins/PasteIt/src/stdafx.h | 42 ++ plugins/PasteIt/src/targetver.h | 8 + plugins/PasteIt/src/version.h | 20 + 13 files changed, 3077 insertions(+) create mode 100644 plugins/PasteIt/src/Options.cpp create mode 100644 plugins/PasteIt/src/Options.h create mode 100644 plugins/PasteIt/src/PasteIt.cpp create mode 100644 plugins/PasteIt/src/PasteToWeb.cpp create mode 100644 plugins/PasteIt/src/PasteToWeb.h create mode 100644 plugins/PasteIt/src/PasteToWeb1.cpp create mode 100644 plugins/PasteIt/src/PasteToWeb1.h create mode 100644 plugins/PasteIt/src/PasteToWeb2.cpp create mode 100644 plugins/PasteIt/src/PasteToWeb2.h create mode 100644 plugins/PasteIt/src/resource.h create mode 100644 plugins/PasteIt/src/stdafx.h create mode 100644 plugins/PasteIt/src/targetver.h create mode 100644 plugins/PasteIt/src/version.h (limited to 'plugins/PasteIt/src') diff --git a/plugins/PasteIt/src/Options.cpp b/plugins/PasteIt/src/Options.cpp new file mode 100644 index 0000000000..49309bc580 --- /dev/null +++ b/plugins/PasteIt/src/Options.cpp @@ -0,0 +1,979 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "StdAfx.h" +#include "Options.h" +#include "resource.h" +#include "PasteToWeb.h" +#include "PasteToWeb1.h" + +extern HINSTANCE hInst; + +#define MODULE "PasteIt" + +Options *Options::instance; +extern PasteToWeb* pasteToWebs[PasteToWeb::pages]; + +struct TCpTable { + UINT cpId; + TCHAR *cpName; +} +cpTable[] = { + { CP_ACP, _T("Use default codepage") }, + { CP_UTF8, _T("UTF-8") }, + { 874, _T("Thai") }, + { 932, _T("Japanese") }, + { 936, _T("Simplified Chinese") }, + { 949, _T("Korean") }, + { 950, _T("Traditional Chinese") }, + { 1250, _T("Central European") }, + { 1251, _T("Cyrillic") }, + { 20866, _T("Cyrillic KOI8-R") }, + { 1252, _T("Latin I") }, + { 1253, _T("Greek") }, + { 1254, _T("Turkish") }, + { 1255, _T("Hebrew") }, + { 1256, _T("Arabic") }, + { 1257, _T("Baltic") }, + { 1258, _T("Vietnamese") }, + { 1361, _T("Korean (Johab)") }, + { CP_UTF7, _T("UTF-7") }, + { 1200, _T("UTF-16") }, + { 1201, _T("UTF-16BE") } +}; + +Options::Options() +{ + defWeb = 0; + codepage = CP_ACP; + autoUTF = true; + confDlg = true; + autoSend = false; + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + webOptions[i] = new WebOptions(i); + } +} + + +Options::~Options() +{ + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + delete webOptions[i]; + webOptions[i] = NULL; + } +} + +void DefWebPageChanged(); + +INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch(msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + CheckDlgButton(hwndDlg, IDC_AUTOUTF, instance->autoUTF ? 1 : 0); + CheckDlgButton(hwndDlg, IDC_CONFDLG, instance->confDlg ? 1 : 0); + CheckDlgButton(hwndDlg, IDC_AUTOSEND, instance->autoSend ? 1 : 0); + + for(int i = 0; i < PasteToWeb::pages; ++i) + { + ComboBox_AddString(GetDlgItem(hwndDlg, IDC_WEBLIST), pasteToWebs[i]->GetName()); + } + + ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_WEBLIST), instance->defWeb); + + InitCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), instance->codepage); + return TRUE; + } + case WM_COMMAND: + { + if(LOWORD(wParam) == IDC_CODEPAGE) + { + if(HIWORD(wParam) == CBN_KILLFOCUS) + { + GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), true, instance->codepage); + } + } + + if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)==CBN_EDITCHANGE) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + return TRUE; + } + case WM_NOTIFY: + { + if(((LPNMHDR)lParam)->code == PSN_APPLY) + { + instance->codepage = GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), false, instance->codepage); + instance->autoUTF = IsDlgButtonChecked(hwndDlg, IDC_AUTOUTF) ? true : false; + instance->confDlg = IsDlgButtonChecked(hwndDlg, IDC_CONFDLG) ? true : false; + instance->autoSend = IsDlgButtonChecked(hwndDlg, IDC_AUTOSEND) ? true : false; + instance->defWeb = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_WEBLIST)); + + DefWebPageChanged(); + + Options::instance->Save(); + } + return TRUE; + } + } + + return FALSE; +} + +class OptsPagesData +{ +public: + OptsPagesData() + : lastPage(0) + { + init = false; + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + webOptions[i] = Options::instance->webOptions[i]->Copy(); + } + } + + ~OptsPagesData() + { + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + delete webOptions[i]; + webOptions[i] = NULL; + } + } + + WebOptions* webOptions[PasteToWeb::pages]; + int lastPage; + bool init; +}; + +struct OptsConfigureData +{ + int page; + std::list tempFormats; +}; + +struct OptsLoginData +{ + std::wstring user; + std::wstring password; +}; + +void ReloadFormatsCombo(HWND hWnd, WebOptions* wo) +{ + while(ComboBox_DeleteString(hWnd, 0) > 0); + int sel = 0; + int i = 0; + for(std::list::iterator it = wo->formats.begin(); it != wo->formats.end(); ++it) + { + ComboBox_AddString(hWnd, it->name.c_str()); + if(it->id == wo->defFormatId) + sel = i; + ++i; + } + if(!wo->formats.empty()) + { + ComboBox_SetCurSel(hWnd, sel); + } +} + +void GetPagesSettings(HWND hwndDlg, OptsPagesData* optsPagesData) +{ + int selected = optsPagesData->lastPage; + int format = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_DEFFORMAT)); + if(format >= 0 && format < (int)optsPagesData->webOptions[selected]->formats.size()) + { + for(std::list::iterator it = optsPagesData->webOptions[selected]->formats.begin(); it != optsPagesData->webOptions[selected]->formats.end(); ++it) + { + if(format-- <= 0) + { + optsPagesData->webOptions[selected]->defFormatId = it->id; + break; + } + } + } + + if(optsPagesData->webOptions[selected]->isSendFileName) + optsPagesData->webOptions[selected]->sendFileName = IsDlgButtonChecked(hwndDlg, IDC_AUTOFORMAT) ? true : false; + if(optsPagesData->webOptions[selected]->isPublicPaste) + optsPagesData->webOptions[selected]->publicPaste = IsDlgButtonChecked(hwndDlg, IDC_PUBLICPASTE) ? true : false; + if(optsPagesData->webOptions[selected]->isCombo1) + { + int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_COMBO1)); + if(sel >= 0 && sel < (int)optsPagesData->webOptions[selected]->combo1Values.size()) + { + for(std::list::iterator it = optsPagesData->webOptions[selected]->combo1Values.begin(); it != optsPagesData->webOptions[selected]->combo1Values.end(); ++it) + { + if(sel-- <= 0) + { + optsPagesData->webOptions[selected]->combo1 = it->id; + break; + } + } + } + } + if(optsPagesData->webOptions[selected]->isPublicPaste) + { + if(IsDlgButtonChecked(hwndDlg, IDC_GUEST)) + { + optsPagesData->webOptions[selected]->pastebinUserKey = _T(""); + } + else + { + TCHAR buf[100]; + Edit_GetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), buf, 100); + optsPagesData->webOptions[selected]->pastebinUserKey = buf; + } + } +} + +INT_PTR CALLBACK Options::DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch(msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + OptsPagesData* optsPagesData = new OptsPagesData(); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)optsPagesData); + + HWND btnhwnd = GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN); + int btSize = Button_GetTextLength(btnhwnd); + if(btSize > 20) + { + SetWindowPos(btnhwnd, NULL, 0, 0, 115, 34, SWP_NOZORDER | SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOACTIVATE | SWP_NOREDRAW); + } + + for(int i = 0; i < PasteToWeb::pages; ++i) + { + ComboBox_AddString(GetDlgItem(hwndDlg, IDC_WEBPAGE), pasteToWebs[i]->GetName()); + } + + ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_WEBPAGE), 0); + ReloadFormatsCombo(GetDlgItem(hwndDlg, IDC_DEFFORMAT), optsPagesData->webOptions[0]); + if(optsPagesData->webOptions[0]->isSendFileName) + CheckDlgButton(hwndDlg, IDC_AUTOFORMAT, optsPagesData->webOptions[0]->sendFileName ? 1 : 0); + else + ShowWindow(GetDlgItem(hwndDlg,IDC_AUTOFORMAT),SW_HIDE); + + if(Options::instance->webOptions[0]->isPublicPaste) + CheckDlgButton(hwndDlg, IDC_PUBLICPASTE, Options::instance->webOptions[0]->publicPaste ? 1 : 0); + else + ShowWindow(GetDlgItem(hwndDlg,IDC_PUBLICPASTE),SW_HIDE); + + if(Options::instance->webOptions[0]->isCombo1) + { + int sel = 0; + int i = 0; + std::wstring &val = Options::instance->webOptions[0]->combo1; + HWND cb = GetDlgItem(hwndDlg, IDC_COMBO1); + for(std::list::iterator it = Options::instance->webOptions[0]->combo1Values.begin(); it != Options::instance->webOptions[0]->combo1Values.end(); ++it) + { + ComboBox_AddString(cb, it->name.c_str()); + if(val == it->id) + sel = i; + ++i; + } + ComboBox_SetCurSel(cb, sel); + Static_SetText(GetDlgItem(hwndDlg,IDC_COMBO1_DESC), Options::instance->webOptions[0]->combo1Desc.c_str()); + } + else + { + ShowWindow(GetDlgItem(hwndDlg,IDC_COMBO1),SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg,IDC_COMBO1_DESC),SW_HIDE); + } + + Edit_LimitText(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), 99); + if(Options::instance->webOptions[0]->isPastebin) + { + std::wstring pastebinUserKey = Options::instance->webOptions[0]->pastebinUserKey; + if(pastebinUserKey.empty()) + { + CheckDlgButton(hwndDlg, IDC_GUEST, TRUE); + Edit_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), FALSE); + Static_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), FALSE); + Button_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), FALSE); + } + else + { + Edit_SetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), pastebinUserKey.c_str()); + } + } + else + { + ShowWindow(GetDlgItem(hwndDlg, IDC_GUEST), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), SW_HIDE); + } + + optsPagesData->init = true; + return TRUE; + } + case WM_COMMAND: + { + OptsPagesData* optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_CONFIGURE) + { + GetPagesSettings(hwndDlg, optsPagesData); + OptsConfigureData d; + d.page = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_WEBPAGE)); + WebOptions* wo = optsPagesData->webOptions[d.page]; + d.tempFormats = wo->formats; + if(DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DLG_CONFIGURE), hwndDlg, DlgProcOptsConfigure, (LPARAM)&d) == IDOK) + { + wo->formats = d.tempFormats; + ReloadFormatsCombo(GetDlgItem(hwndDlg, IDC_DEFFORMAT), wo); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + } + else if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_PASTEBIN_LOGIN) + { + OptsLoginData d; + if(DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DLG_PASTEBIN_LOGIN), hwndDlg, DlgProcOptsLogin, (LPARAM)&d) == IDOK) + { + PasteToWeb1 *web = (PasteToWeb1*)pasteToWebs[optsPagesData->lastPage]; + Edit_SetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), web->GetUserKey(d.user, d.password).c_str()); + } + } + else if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_GUEST) + { + BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_GUEST) ? FALSE : TRUE; + Edit_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), enabled); + Static_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), enabled); + Button_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), enabled); + } + else if(HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_WEBPAGE) + { + GetPagesSettings(hwndDlg, optsPagesData); + optsPagesData->init = false; + optsPagesData->lastPage = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_WEBPAGE)); + ReloadFormatsCombo(GetDlgItem(hwndDlg, IDC_DEFFORMAT), optsPagesData->webOptions[optsPagesData->lastPage]); + if(optsPagesData->webOptions[optsPagesData->lastPage]->isSendFileName) + { + ShowWindow(GetDlgItem(hwndDlg,IDC_AUTOFORMAT),SW_SHOW); + CheckDlgButton(hwndDlg, IDC_AUTOFORMAT, optsPagesData->webOptions[optsPagesData->lastPage]->sendFileName ? 1 : 0); + } + else + ShowWindow(GetDlgItem(hwndDlg,IDC_AUTOFORMAT),SW_HIDE); + + if(optsPagesData->webOptions[optsPagesData->lastPage]->isPublicPaste) + { + ShowWindow(GetDlgItem(hwndDlg,IDC_PUBLICPASTE),SW_SHOW); + CheckDlgButton(hwndDlg, IDC_PUBLICPASTE, optsPagesData->webOptions[optsPagesData->lastPage]->publicPaste ? 1 : 0); + } + else + ShowWindow(GetDlgItem(hwndDlg,IDC_PUBLICPASTE),SW_HIDE); + + if(optsPagesData->webOptions[optsPagesData->lastPage]->isCombo1) + { + ShowWindow(GetDlgItem(hwndDlg,IDC_COMBO1),SW_SHOW); + ShowWindow(GetDlgItem(hwndDlg,IDC_COMBO1_DESC),SW_SHOW); + int sel = 0; + int i = 0; + std::wstring &val = optsPagesData->webOptions[optsPagesData->lastPage]->combo1; + HWND cb = GetDlgItem(hwndDlg, IDC_COMBO1); + while(ComboBox_DeleteString(cb, 0) > 0); + for(std::list::iterator it = optsPagesData->webOptions[optsPagesData->lastPage]->combo1Values.begin(); it != optsPagesData->webOptions[optsPagesData->lastPage]->combo1Values.end(); ++it) + { + ComboBox_AddString(cb, it->name.c_str()); + if(val == it->id) + sel = i; + ++i; + } + ComboBox_SetCurSel(cb, sel); + SetWindowText(GetDlgItem(hwndDlg,IDC_COMBO1_DESC), optsPagesData->webOptions[optsPagesData->lastPage]->combo1Desc.c_str()); + } + else + { + ShowWindow(GetDlgItem(hwndDlg,IDC_COMBO1),SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg,IDC_COMBO1_DESC),SW_HIDE); + } + + + if(optsPagesData->webOptions[optsPagesData->lastPage]->isPastebin) + { + ShowWindow(GetDlgItem(hwndDlg, IDC_GUEST), SW_SHOW); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), SW_SHOW); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), SW_SHOW); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), SW_SHOW); + std::wstring pastebinUserKey = optsPagesData->webOptions[optsPagesData->lastPage]->pastebinUserKey; + if(pastebinUserKey.empty()) + { + CheckDlgButton(hwndDlg, IDC_GUEST, TRUE); + Edit_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), FALSE); + Static_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), FALSE); + Button_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), FALSE); + } + else + { + CheckDlgButton(hwndDlg, IDC_GUEST, FALSE); + Edit_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), TRUE); + Static_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), TRUE); + Button_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), TRUE); + } + + Edit_SetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), pastebinUserKey.c_str()); + } + else + { + ShowWindow(GetDlgItem(hwndDlg, IDC_GUEST), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), SW_HIDE); + } + + optsPagesData->init = true; + } + + if (optsPagesData->init && ((HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) != IDC_CONFIGURE && LOWORD(wParam) != IDC_PASTEBIN_LOGIN) || (HIWORD(wParam)==CBN_SELCHANGE && LOWORD(wParam) != IDC_WEBPAGE) || HIWORD(wParam) == EN_CHANGE)) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + return TRUE; + } + case WM_NOTIFY: + { + if(((LPNMHDR)lParam)->code == PSN_APPLY) + { + OptsPagesData* optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + GetPagesSettings(hwndDlg, optsPagesData); + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + *Options::instance->webOptions[i] = *optsPagesData->webOptions[i]; + } + + Options::instance->Save(); + } + return TRUE; + } + case WM_CLOSE: + { + OptsPagesData* optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + delete optsPagesData; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, NULL); + break; + } + } + + return FALSE; +} + +void SelectLbConfigure(HWND hwndDlg, int sel, OptsConfigureData* optsConfigureData) +{ + if(sel >= 0 && sel < (int)optsConfigureData->tempFormats.size()) + { + Button_Enable(GetDlgItem(hwndDlg, IDC_DELETE), TRUE); + if(sel == 0) + Button_Enable(GetDlgItem(hwndDlg, IDC_UP), FALSE); + else + Button_Enable(GetDlgItem(hwndDlg, IDC_UP), TRUE); + if(sel + 1 == optsConfigureData->tempFormats.size()) + Button_Enable(GetDlgItem(hwndDlg, IDC_DOWN), FALSE); + else + Button_Enable(GetDlgItem(hwndDlg, IDC_DOWN), TRUE); + } + else + { + Button_Enable(GetDlgItem(hwndDlg, IDC_DELETE), FALSE); + Button_Enable(GetDlgItem(hwndDlg, IDC_UP), FALSE); + Button_Enable(GetDlgItem(hwndDlg, IDC_DOWN), FALSE); + } +} + +INT_PTR CALLBACK Options::DlgProcOptsConfigure(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch(msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + OptsConfigureData* optsConfigureData = (OptsConfigureData*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + for(std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) + { + ListBox_AddString(lb, it->name.c_str()); + } + + SelectLbConfigure(hwndDlg, -1, optsConfigureData); + return TRUE; + } + case WM_COMMAND: + { + if (HIWORD(wParam) == BN_CLICKED) + { + if (LOWORD(wParam) == IDOK) + { + EndDialog(hwndDlg, IDOK); + } + else if (LOWORD(wParam) == IDCANCEL) + { + EndDialog(hwndDlg, IDCANCEL); + } + else if (LOWORD(wParam) == IDC_DELETE) + { + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(lb); + if(sel >= 0) + { + ListBox_DeleteString(lb, sel); + int i = sel; + for(std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) + { + if(i-- <= 0) + { + optsConfigureData->tempFormats.erase(it); + ListBox_SetCurSel(lb, sel); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + break; + } + } + } + } + else if (LOWORD(wParam) == IDC_UP) + { + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(lb); + if(sel > 0) + { + int i = sel; + for(std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) + { + if(i-- <= 0) + { + PasteFormat pf = *it; + std::list::iterator prevIt = it; + --prevIt; + optsConfigureData->tempFormats.erase(it); + optsConfigureData->tempFormats.insert(prevIt, pf); + ListBox_DeleteString(lb, sel--); + ListBox_InsertString(lb, sel, pf.name.c_str()); + ListBox_SetCurSel(lb, sel); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + break; + } + } + } + } + else if (LOWORD(wParam) == IDC_DOWN) + { + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(lb); + if(sel >= 0 && sel + 1 < (int)optsConfigureData->tempFormats.size()) + { + int i = sel; + for(std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) + { + if(i-- <= 0) + { + PasteFormat pf = *it; + std::list::iterator nextIt = it; + ++(++nextIt); + optsConfigureData->tempFormats.erase(it); + optsConfigureData->tempFormats.insert(nextIt, pf); + ListBox_DeleteString(lb, sel++); + ListBox_InsertString(lb, sel, pf.name.c_str()); + ListBox_SetCurSel(lb, sel); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + break; + } + } + } + } + else if(LOWORD(wParam) == IDC_DOWNLOAD) + { + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + while(ListBox_DeleteString(lb, 0) > 0); + SelectLbConfigure(hwndDlg, -1, optsConfigureData); + optsConfigureData->tempFormats = pasteToWebs[optsConfigureData->page]->GetFormats(); + for(std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) + { + ListBox_AddString(lb, it->name.c_str()); + } + } + else if(LOWORD(wParam) == IDC_RESTORE) + { + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + while(ListBox_DeleteString(lb, 0) > 0); + SelectLbConfigure(hwndDlg, -1, optsConfigureData); + optsConfigureData->tempFormats = pasteToWebs[optsConfigureData->page]->GetDefFormats(); + for(std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) + { + ListBox_AddString(lb, it->name.c_str()); + } + } + } + else if(HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_FORMATTING) + { + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMATTING)); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + } + return TRUE; + } + case WM_VKEYTOITEM: + if(LOWORD(wParam) == VK_DELETE && (HWND)lParam == GetDlgItem(hwndDlg, IDC_FORMATTING)) + { + DlgProcOptsConfigure(hwndDlg, WM_COMMAND, MAKELONG(IDC_DELETE, BN_CLICKED), NULL); + return -2; + } + return -1; + case WM_NOTIFY: + { + return TRUE; + } + } + + return FALSE; +} + +INT_PTR CALLBACK Options::DlgProcOptsLogin(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch(msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + Edit_LimitText(GetDlgItem(hwndDlg, IDC_PASTEBIN_USER), 99); + Edit_LimitText(GetDlgItem(hwndDlg, IDC_PASTEBIN_PASSWORD), 99); + return TRUE; + } + case WM_COMMAND: + { + if (HIWORD(wParam) == BN_CLICKED) + { + if (LOWORD(wParam) == IDOK) + { + TCHAR buf[100]; + OptsLoginData* optsLoginData = (OptsLoginData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + Edit_GetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_USER), buf, 100); + optsLoginData->user = buf; + Edit_GetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_PASSWORD), buf, 100); + optsLoginData->password = buf; + EndDialog(hwndDlg, IDOK); + } + else if (LOWORD(wParam) == IDCANCEL) + { + EndDialog(hwndDlg, IDCANCEL); + } + } + return TRUE; + } + case WM_NOTIFY: + { + return TRUE; + } + } + + return FALSE; +} + +unsigned int Options::GetCodepageCB(HWND hwndCB, bool errorReport, unsigned int defCp) +{ + int selCpIdx = ComboBox_GetCurSel(hwndCB); + if(selCpIdx < 0) + { + TCHAR text[128]; + ComboBox_GetText(hwndCB, text, 128); + TCHAR * stopOn = NULL; + long cp = _tcstol(text, &stopOn, 10); + if(errorReport && (stopOn == text || *stopOn != '\0' || cp < 0 || cp > 0xffff)) + { + MessageBox(GetParent(hwndCB), TranslateT("You've entered invalid codepage. Select codepage from combo box or enter correct number."), TranslateT("Invalid codepage"), MB_OK | MB_ICONERROR); + SetFocus(hwndCB); + SetCodepageCB(hwndCB, defCp); + return defCp; + } + + return cp; + } + else return cpTable[selCpIdx].cpId; +} + +void Options::SetDefWeb(int web) +{ + defWeb = web; + DBWriteContactSettingWString(0, MODULE, "defWeb", pasteToWebs[web]->GetName()); + DefWebPageChanged(); +} + +void Options::InitCodepageCB(HWND hwndCB, unsigned int codepage) +{ + int cpCount = sizeof(cpTable) / sizeof(cpTable[0]); + int selCpIdx = -1; + for(int i = 0; i < cpCount; ++i) + { + ComboBox_AddString(hwndCB, TranslateTS(cpTable[i].cpName)); + if(cpTable[i].cpId == codepage) + selCpIdx = i; + } + + if(selCpIdx == -1) + { + TCHAR buf[10]; + _stprintf_s(buf, 10, _T("%d"), codepage); + ComboBox_SetText(hwndCB, buf); + } + else + { + ComboBox_SetCurSel(hwndCB, selCpIdx); + } + + ComboBox_LimitText(hwndCB, 127); +} + +void Options::SetCodepageCB(HWND hwndCB, unsigned int codepage) +{ + int cpCount = sizeof(cpTable) / sizeof(cpTable[0]); + int selCpIdx = -1; + for(int i = 0; i < cpCount; ++i) + { + if(cpTable[i].cpId == codepage) + selCpIdx = i; + } + + if(selCpIdx == -1) + { + TCHAR buf[10]; + _stprintf_s(buf, 10, _T("%d"), codepage); + ComboBox_SetText(hwndCB, buf); + } + else + { + ComboBox_SetCurSel(hwndCB, selCpIdx); + } +} + +int Options::InitOptions(WPARAM wParam, LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp = {0}; + + odp.cbSize = sizeof(odp); + odp.position = 100000000; + odp.hInstance = hInst; + odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR; + odp.ptszTitle = LPGENT("Paste It"); + odp.ptszGroup = LPGENT("Services"); + + odp.ptszTab = LPGENT("Main"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAIN); + odp.pfnDlgProc = Options::DlgProcOptsMain; + Options_AddPage(wParam, &odp); + + odp.ptszTab = LPGENT("Web page"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_PAGES); + odp.pfnDlgProc = Options::DlgProcOptsPages; + Options_AddPage(wParam, &odp); + + return 0; +} + +void Options::Save() +{ + DBWriteContactSettingWString(0, MODULE, "defWeb", pasteToWebs[defWeb]->GetName()); + DBWriteContactSettingDword(0, MODULE, "codepage", codepage); + DBWriteContactSettingByte(0, MODULE, "autoUTF", autoUTF ? 1 : 0); + DBWriteContactSettingByte(0, MODULE, "confDlg", confDlg ? 1 : 0); + DBWriteContactSettingByte(0, MODULE, "autoSend", autoSend ? 1 : 0); + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + char buf[256]; + TCHAR* name = pasteToWebs[i]->GetName(); + int j = 0; + while(name[j]) + { + buf[j] = (char)name[j]; + ++j; + } + buf[j++] = '_'; + + strcpy_s(buf + j, 256 - j, "formats"); + std::wstring forms; + for(std::list::iterator it = webOptions[i]->formats.begin(); it != webOptions[i]->formats.end(); ++it) + { + forms += it->id + L'=' + it->name + L';'; + } + + DBWriteContactSettingWString(0, MODULE, buf, forms.c_str()); + + strcpy_s(buf + j, 256 - j, "defFormatId"); + DBWriteContactSettingWString(0, MODULE, buf, webOptions[i]->defFormatId.c_str()); + + if(webOptions[i]->isSendFileName) + { + strcpy_s(buf + j, 256 - j, "sendFileName"); + DBWriteContactSettingByte(0, MODULE, buf, webOptions[i]->sendFileName ? 1 : 0); + } + + if(webOptions[i]->isPublicPaste) + { + strcpy_s(buf + j, 256 - j, "publicPaste"); + DBWriteContactSettingByte(0, MODULE, buf, webOptions[i]->publicPaste ? 1 : 0); + } + + if(webOptions[i]->isCombo1) + { + strcpy_s(buf + j, 256 - j, "combo1"); + DBWriteContactSettingWString(0, MODULE, buf, webOptions[i]->combo1.c_str()); + } + + if(webOptions[i]->isPastebin) + { + strcpy_s(buf + j, 256 - j, "pastebinUserKey"); + DBWriteContactSettingWString(0, MODULE, buf, webOptions[i]->pastebinUserKey.c_str()); + } + } +} + +void Options::Load() +{ + DBVARIANT defWebV; + if(!DBGetContactSettingWString(0, MODULE, "defWeb", &defWebV)) + { + for(int i = 0; i < PasteToWeb::pages; ++i) + { + if(!wcscmp(pasteToWebs[i]->GetName(), defWebV.pwszVal)) + { + defWeb = i; + break; + } + } + DBFreeVariant(&defWebV); + } + codepage = DBGetContactSettingDword(0, MODULE, "codepage", CP_ACP); + autoUTF = DBGetContactSettingByte(0, MODULE, "autoUTF", 1) ? true : false; + confDlg = DBGetContactSettingByte(0, MODULE, "confDlg", 1) ? true : false; + autoSend = DBGetContactSettingByte(0, MODULE, "autoSend", 0) ? true : false; + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + char buf[256]; + TCHAR* name = pasteToWebs[i]->GetName(); + int j = 0; + while(name[j]) + { + buf[j] = (char)name[j]; + ++j; + } + buf[j++] = '_'; + + strcpy_s(buf + j, 256 - j, "formats"); + DBVARIANT forms; + if(!DBGetContactSettingWString(0, MODULE, buf, &forms)) + { + webOptions[i]->formats.clear(); + int k = 0; + wchar_t * id = forms.pwszVal; + wchar_t * name = NULL; + while(forms.pwszVal[k]) + { + if(forms.pwszVal[k] == L'=') + { + forms.pwszVal[k] = 0; + name = forms.pwszVal + k + 1; + } + else if(forms.pwszVal[k] == L';') + { + forms.pwszVal[k] = 0; + PasteFormat pf; + pf.id = id; + pf.name = name; + webOptions[i]->formats.push_back(pf); + id = forms.pwszVal + k + 1; + } + + ++k; + } + + DBFreeVariant(&forms); + } + + strcpy_s(buf + j, 256 - j, "defFormatId"); + DBVARIANT defForm; + if(!DBGetContactSettingWString(0, MODULE, buf, &defForm)) + { + webOptions[i]->defFormatId = defForm.pwszVal; + DBFreeVariant(&defForm); + } + + if(webOptions[i]->isSendFileName) + { + strcpy_s(buf + j, 256 - j, "sendFileName"); + webOptions[i]->sendFileName = DBGetContactSettingByte(0, MODULE, buf, 1) ? true : false; + } + + if(webOptions[i]->isPublicPaste) + { + strcpy_s(buf + j, 256 - j, "publicPaste"); + webOptions[i]->publicPaste = DBGetContactSettingByte(0, MODULE, buf, 0) ? true : false; + } + + if(webOptions[i]->isCombo1) + { + strcpy_s(buf + j, 256 - j, "combo1"); + DBVARIANT combo1; + if(!DBGetContactSettingWString(0, MODULE, buf, &combo1)) + { + webOptions[i]->combo1 = combo1.pwszVal; + DBFreeVariant(&combo1); + } + } + + if(webOptions[i]->isPastebin) + { + strcpy_s(buf + j, 256 - j, "pastebinUserKey"); + DBVARIANT pastebinUserKey; + if(!DBGetContactSettingWString(0, MODULE, buf, &pastebinUserKey)) + { + webOptions[i]->pastebinUserKey = pastebinUserKey.pwszVal; + DBFreeVariant(&pastebinUserKey); + } + } + } +} + +WebOptions::WebOptions(int serv) + :server(serv), + formats(pasteToWebs[serv]->GetDefFormats()), + sendFileName(true), + isSendFileName(true), + publicPaste(false), + isPublicPaste(false), + isCombo1(false), + isPastebin(false) +{ + defFormatId = formats.front().id; +} + + +WebOptions::~WebOptions() +{ +} + +WebOptions* WebOptions::Copy() +{ + return new WebOptions(*this); +} diff --git a/plugins/PasteIt/src/Options.h b/plugins/PasteIt/src/Options.h new file mode 100644 index 0000000000..9e58e44d7f --- /dev/null +++ b/plugins/PasteIt/src/Options.h @@ -0,0 +1,72 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once +#include "PasteToWeb.h" + +class WebOptions +{ +public: + WebOptions(int serv); + virtual ~WebOptions(); + virtual WebOptions* Copy(); + int server; + bool isSendFileName; + bool isPublicPaste; + bool isCombo1; + std::list combo1Values; + std::wstring combo1Desc; + bool isPastebin; + + std::list formats; + std::wstring defFormatId; + bool sendFileName; + bool publicPaste; + std::wstring combo1; + std::wstring pastebinUserKey; +}; + +class Options +{ +public: + Options(); + ~Options(); + static int InitOptions(WPARAM wParam, LPARAM lParam); + + static INT_PTR CALLBACK DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK DlgProcOptsConfigure(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK DlgProcOptsLogin(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + + static void InitCodepageCB(HWND hwndCB, unsigned int codepage); + static void SetCodepageCB(HWND hwndCB, unsigned int codepage); + static unsigned int GetCodepageCB(HWND hwndCB, bool errorReport, unsigned int defCp); + + static Options *instance; + void Save(); + void Load(); + + int defWeb; + unsigned int codepage; + bool autoUTF; + bool confDlg; + bool autoSend; + void SetDefWeb(int web); + WebOptions* webOptions[PasteToWeb::pages]; +}; + diff --git a/plugins/PasteIt/src/PasteIt.cpp b/plugins/PasteIt/src/PasteIt.cpp new file mode 100644 index 0000000000..ce38743f68 --- /dev/null +++ b/plugins/PasteIt/src/PasteIt.cpp @@ -0,0 +1,564 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "stdafx.h" +#include "PasteToWeb1.h" +#include "PasteToWeb2.h" +#include "version.h" +#include "resource.h" +#include "Options.h" + +// {1AAC15E8-DCEC-4050-B66F-2AA0E6120C22} +#define MIID_PASTEIT { 0x1aac15e8, 0xdcec, 0x4050, { 0xb6, 0x6f, 0x2a, 0xa0, 0xe6, 0x12, 0xc, 0x22 } } + + +PasteToWeb* pasteToWebs[PasteToWeb::pages]; +std::map* contactWindows; +DWORD gMirandaVersion; + +extern HINSTANCE hInst; +HANDLE hModulesLoaded, hTabsrmmButtonPressed; +HANDLE g_hNetlibUser; +HANDLE hPrebuildContactMenu; +HANDLE hServiceContactMenu; +HGENMENU hContactMenu; +HGENMENU hWebPageMenus[PasteToWeb::pages]; +HANDLE hMainIcon; +HANDLE hOptionsInit; +HANDLE hWindowEvent = NULL; +HINSTANCE hInst; + +#define MODULE "PasteIt" +#define FROM_CLIPBOARD 10 +#define FROM_FILE 11 +#define DEF_PAGES_START 20 +#define MS_PASTEIT_CONTACTMENU "PasteIt/ContactMenu" + +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + MIID_PASTEIT +}; + +XML_API xi = {0}; +int hLangpack = 0; + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + hInst = hModule; + return TRUE; +} + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + gMirandaVersion = mirandaVersion; + if (mirandaVersion < PLUGIN_MAKE_VERSION(0, 8, 0, 0)) + return NULL; + + return &pluginInfo; +} + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_PASTEIT, MIID_LAST}; + +std::wstring GetFile() +{ + TCHAR filter[512]; + _tcscpy_s(filter, 512, TranslateT("All Files (*.*)")); + memcpy(filter + _tcslen(filter), _T("\0*.*\0"), 6 * sizeof(TCHAR)); + TCHAR stzFilePath[1024]; + stzFilePath[0] = 0; + stzFilePath[1] = 0; + OPENFILENAME ofn = {0}; + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = 0; + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.lpstrFile = stzFilePath; + ofn.lpstrTitle = TranslateT("Paste It - Select file"); + ofn.nMaxFile = 1024; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR; + if(GetOpenFileName(&ofn)) + { + return stzFilePath; + } + + return L""; +} + +void PasteIt(HANDLE hContact, int mode) +{ + PasteToWeb* pasteToWeb = pasteToWebs[Options::instance->defWeb]; + if(mode == FROM_CLIPBOARD) + { + pasteToWeb->FromClipboard(); + } + else if(mode == FROM_FILE) + { + std::wstring file = GetFile(); + if(file.length() > 0) + { + pasteToWeb->FromFile(file); + } + else return; + } + else return; + + if(pasteToWeb->szFileLink[0] == 0 && pasteToWeb->error != NULL) + { + MessageBox(NULL, pasteToWeb->error, TranslateT("Error"), MB_OK | MB_ICONERROR); + } + else if(hContact != NULL && pasteToWeb->szFileLink[0] != 0) + { + char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if (szProto && (INT_PTR)szProto != CALLSERVICE_NOTFOUND) + { + BOOL isChat = DBGetContactSettingByte(hContact, szProto, "ChatRoom", 0); + if(Options::instance->autoSend) + { + if(!isChat) + { + DBEVENTINFO dbei = {0}; + dbei.cbSize = sizeof(dbei); + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.flags = DBEF_SENT; + dbei.szModule = szProto; + dbei.timestamp = (DWORD)time(NULL); + dbei.cbBlob = (DWORD)strlen(pasteToWeb->szFileLink) + 1; + dbei.pBlob = (PBYTE)pasteToWeb->szFileLink; + CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei); + CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)pasteToWeb->szFileLink); + } + else + { + // PSS_MESSAGE is not compatible with chat rooms + // there are no simple method to send text to all users + // in chat room. + // First I check if protocol is unicode or ascii. + BOOL isUnicodePlugin = TRUE; + PROTOACCOUNT* protoAc = ProtoGetAccount(szProto); + if(protoAc != NULL) + { + // protoAc->ppro is abstract class, that contains + // methods implemented in protocol ddl`s segment. + // Method address in vptr table must be converted + // to hInstance of protocol dll. + PROTO_INTERFACE* protoInt = protoAc->ppro; + MEMORY_BASIC_INFORMATION mb; + INT_PTR *vptr = *(INT_PTR**)&protoAc->ppro; + INT_PTR *vtable = (INT_PTR *)*vptr; + if(VirtualQuery((void*)vtable[0], &mb, sizeof(MEMORY_BASIC_INFORMATION))) + { + typedef PLUGININFOEX * (__cdecl * Miranda_Plugin_InfoEx) ( DWORD mirandaVersion ); + HINSTANCE hInst = (HINSTANCE)mb.AllocationBase; + // Now I can get PLUGININFOEX from protocol + Miranda_Plugin_InfoEx infoEx = (Miranda_Plugin_InfoEx) GetProcAddress(hInst, "MirandaPluginInfoEx"); + PLUGININFOEX* pi = NULL; + if(infoEx != NULL) + { + pi = infoEx(gMirandaVersion); + } + // If PLUGININFOEX flags contains UNICODE_AWARE, + // this mean that protocol is unicode. + if(pi != NULL && pi->cbSize == sizeof(PLUGININFOEX)) + { + isUnicodePlugin = pi->flags & UNICODE_AWARE; + } + } + } + + // Next step is to get all protocol sessions and find + // one with correct hContact + GC_INFO gci = {0}; + GCDEST gcd = {0}; + GCEVENT gce = {0}; + int cnt = (int)CallService(MS_GC_GETSESSIONCOUNT, 0, (LPARAM)szProto); + for (int i = 0; i < cnt ; i++ ) + { + gci.iItem = i; + gci.pszModule = szProto; + gci.Flags = BYINDEX | HCONTACT | ID; + CallService(MS_GC_GETINFO, 0, (LPARAM)(GC_INFO *) &gci); + if (gci.hContact == hContact) + { + // In this place session was finded, gci.pszID contains + // session ID, but it is in unicode or ascii format, + // depends on protocol wersion + gcd.pszModule = szProto; + gcd.iType = GC_EVENT_SENDMESSAGE; + gcd.ptszID = gci.pszID; + gce.cbSize = sizeof(GCEVENT); + gce.pDest = &gcd; + gce.bIsMe = TRUE; + gce.dwFlags = isUnicodePlugin ? (GCEF_ADDTOLOG | GC_UNICODE) : GCEF_ADDTOLOG; + wchar_t* s = NULL; + if(isUnicodePlugin) + { + // If session ID is in unicode, text must be too in unicode + s = mir_a2u_cp(pasteToWeb->szFileLink, CP_ACP); + gce.ptszText = s; + } + else + { + // If session ID is in ascii, text must be too in ascii + gce.pszText = pasteToWeb->szFileLink; + } + gce.time = time(NULL); + CallService(MS_GC_EVENT, 0, (LPARAM)(GCEVENT *) &gce); + if(s != NULL) + mir_free(s); + break; + } + } + } + + // Send message to focus window + CallServiceSync(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0); + } + else + { + if(isChat) + { + // MS_MSG_SENDMESSAGE in incompatible with chat rooms, + // because it sends text to IDC_MESSAGE window, + // but in chat rooms is only IDC_CHAT_MESSAGE window. + // contactWindows map contains all opened hContact + // with assaigned to them chat windows. + // This map is prepared in ME_MSG_WINDOWEVENT event. + std::map::iterator it = contactWindows->find(hContact); + if(it != contactWindows->end()) + { + // it->second is imput window, so now I can send to them + // new text. Afterr all is sended MS_MSG_SENDMESSAGE + // to focus window. + SendMessage(it->second, EM_SETSEL, -1, SendMessage(it->second, WM_GETTEXTLENGTH, 0, 0)); + SendMessageA(it->second, EM_REPLACESEL, FALSE, (LPARAM)pasteToWeb->szFileLink); + CallServiceSync(MS_MSG_SENDMESSAGE, (WPARAM)hContact, NULL); + } + else + { + // If window do not exist, maybe it is not chat + CallServiceSync(MS_MSG_SENDMESSAGE, (WPARAM)hContact, (LPARAM)pasteToWeb->szFileLink); + } + } + else + { + CallServiceSync(MS_MSG_SENDMESSAGE, (WPARAM)hContact, (LPARAM)pasteToWeb->szFileLink); + } + } + } + } +} + +int TabsrmmButtonPressed(WPARAM wParam, LPARAM lParam) +{ + CustomButtonClickData *cbc = (CustomButtonClickData *)lParam; + HANDLE hContact = (HANDLE)wParam; + + if (!strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == 1 && hContact) + { + if (cbc->flags == BBCF_ARROWCLICKED) + { + HMENU hMenu = CreatePopupMenu(); + if (hMenu) + { + AppendMenu(hMenu, MF_STRING, FROM_CLIPBOARD, TranslateT("Paste from clipboard")); + AppendMenu(hMenu, MF_STRING, FROM_FILE, TranslateT("Paste from file")); + HMENU hDefMenu = CreatePopupMenu(); + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + UINT flags = MF_STRING; + if(Options::instance->defWeb == i) + flags |= MF_CHECKED; + + AppendMenu(hDefMenu, flags, DEF_PAGES_START + i, pasteToWebs[i]->GetName()); + } + + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hDefMenu, TranslateT("Default web page")); + + POINT pt; + GetCursorPos(&pt); + HWND hwndBtn = WindowFromPoint(pt); + if (hwndBtn) + { + RECT rc; + GetWindowRect(hwndBtn, &rc); + SetForegroundWindow(cbc->hwndFrom); + int selected = TrackPopupMenu(hMenu, TPM_RETURNCMD, rc.left, rc.bottom, 0, cbc->hwndFrom, 0); + if (selected != 0) + { + if(selected >= DEF_PAGES_START) + { + Options::instance->SetDefWeb(selected - DEF_PAGES_START); + } + else + { + PasteIt(hContact, selected); + } + } + } + + DestroyMenu(hDefMenu); + DestroyMenu(hMenu); + } + } + else + { + PasteIt(hContact, FROM_CLIPBOARD); + } + } + + return 0; +} + +int PrebuildContactMenu(WPARAM wParam, LPARAM lParam) +{ + bool bIsContact = false; + + char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); + if (szProto && (INT_PTR)szProto != CALLSERVICE_NOTFOUND) bIsContact = (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) ? true : false; + + CLISTMENUITEM mi = {0}; + mi.cbSize = sizeof(mi); + mi.flags = CMIM_FLAGS; + + if (!bIsContact) mi.flags |= CMIF_HIDDEN; + else mi.flags &= ~CMIF_HIDDEN; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenu, (LPARAM)&mi); + + return 0; +} + +INT_PTR ContactMenuService(WPARAM wParam, LPARAM lParam) +{ + if(lParam >= DEF_PAGES_START) + { + Options::instance->SetDefWeb(lParam - DEF_PAGES_START); + } + else + { + HANDLE hContact = (HANDLE)wParam; + PasteIt(hContact, lParam); + } + return 0; +} + +void InitIcolib() +{ + TCHAR stzFile[MAX_PATH]; + + SKINICONDESC sid = {0}; + sid.cbSize = sizeof(sid); + sid.cx = sid.cy = 16; + sid.ptszDefaultFile = stzFile; + sid.ptszSection = LPGENT("Paste It"); + sid.flags = SIDF_ALL_TCHAR; + + GetModuleFileName(hInst, stzFile, MAX_PATH); + + sid.pszName = "PasteIt_main"; + sid.ptszDescription = LPGENT("Paste It"); + sid.iDefaultIndex = -IDI_MENU; + hMainIcon = Skin_AddIcon(&sid); +} + +void InitMenuItems() +{ + CLISTMENUITEM mi = {0}; + CLISTMENUITEM mi2 = {0}; + + mi.cbSize = sizeof(mi); + mi.flags = CMIF_ROOTPOPUP | CMIF_ICONFROMICOLIB | CMIF_TCHAR; + mi.icolibItem = hMainIcon; + mi.position = 3000090005; + mi.ptszName = _T("Paste It"); + + hContactMenu = Menu_AddContactMenuItem(&mi); + + memset(&mi, 0, sizeof(mi)); + mi.cbSize = sizeof(mi); + mi.flags = CMIF_CHILDPOPUP | CMIF_ROOTHANDLE | CMIF_TCHAR; + mi.pszService = MS_PASTEIT_CONTACTMENU; + mi.hParentMenu = hContactMenu; + mi.popupPosition = FROM_CLIPBOARD; + mi.ptszName = _T("Paste from clipboard"); + Menu_AddContactMenuItem(&mi); + + mi.popupPosition = FROM_FILE; + mi.ptszName = _T("Paste from file"); + Menu_AddContactMenuItem(&mi); + + mi.popupPosition = DEF_PAGES_START - 1; + mi.ptszName = _T("Default web page"); + HGENMENU hDefWebMenu = Menu_AddContactMenuItem(&mi); + + mi2.cbSize = sizeof(mi2); + mi2.pszService = MS_PASTEIT_CONTACTMENU; + mi2.hParentMenu = hDefWebMenu; + for(int i = 0 ; i < PasteToWeb::pages; ++i) + { + mi2.flags = CMIF_CHILDPOPUP | CMIF_ROOTHANDLE | CMIF_TCHAR; + if(Options::instance->defWeb == i) + mi2.flags |= CMIF_CHECKED; + mi2.ptszName = pasteToWebs[i]->GetName(); + mi2.popupPosition = mi2.position = DEF_PAGES_START + i; + hWebPageMenus[i] = Menu_AddContactMenuItem(&mi2); + } + + hPrebuildContactMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PrebuildContactMenu); +} + +void DefWebPageChanged() +{ + CLISTMENUITEM mi = {0}; + mi.cbSize = sizeof(mi); + + for (int i = 0; i < PasteToWeb::pages; i++) + { + mi.flags = CMIM_FLAGS; + if (Options::instance->defWeb == i) + { + mi.flags |= CMIF_CHECKED; + } + + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hWebPageMenus[i], (LPARAM)&mi); + } +} + +void InitTabsrmmButton() +{ + if (ServiceExists(MS_BB_ADDBUTTON)) + { + BBButton btn = {0}; + btn.cbSize = sizeof(btn); + btn.dwButtonID = 1; + btn.pszModuleName = MODULE; + btn.dwDefPos = 110; + btn.hIcon = hMainIcon; + btn.bbbFlags = BBBF_ISARROWBUTTON | BBBF_ISIMBUTTON | BBBF_ISLSIDEBUTTON | BBBF_CANBEHIDDEN | BBBF_ISCHATBUTTON; + btn.ptszTooltip = TranslateT("Paste It"); + CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&btn); + if(hTabsrmmButtonPressed != NULL) + { + UnhookEvent(hTabsrmmButtonPressed); + } + + hTabsrmmButtonPressed = HookEvent(ME_MSG_BUTTONPRESSED, TabsrmmButtonPressed); + } +} + +int WindowEvent(WPARAM wParam, MessageWindowEventData* lParam) +{ + if(lParam->uType == MSG_WINDOW_EVT_OPEN) + { + char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)lParam->hContact, 0); + if (szProto && (INT_PTR)szProto != CALLSERVICE_NOTFOUND) + { + if(DBGetContactSettingByte(lParam->hContact, szProto, "ChatRoom", 0)) + { + (*contactWindows)[lParam->hContact] = lParam->hwndInput; + } + } + } + else if(lParam->uType == MSG_WINDOW_EVT_CLOSE) + { + std::map::iterator it = contactWindows->find(lParam->hContact); + if(it != contactWindows->end()) + { + contactWindows->erase(it); + } + } + + return 0; +} + +int ModulesLoaded(WPARAM wParam, LPARAM lParam) +{ + InitIcolib(); + InitMenuItems(); + InitTabsrmmButton(); + hWindowEvent = HookEvent(ME_MSG_WINDOWEVENT, (MIRANDAHOOK)WindowEvent); + + return 0; +} + +extern "C" int __declspec(dllexport) Load(void) +{ + mir_getXI(&xi); + mir_getLP(&pluginInfo); + NETLIBUSER nlu = {0}; + nlu.cbSize = sizeof(nlu); + nlu.flags = NUF_TCHAR | NUF_OUTGOING | NUF_HTTPCONNS; + nlu.szSettingsModule = MODULE; + nlu.ptszDescriptiveName = TranslateT("Paste It HTTP connections"); + g_hNetlibUser = ( HANDLE )CallService( MS_NETLIB_REGISTERUSER, 0, ( LPARAM )&nlu ); + + pasteToWebs[0] = new PasteToWeb1(); + pasteToWebs[0]->pageIndex = 0; + pasteToWebs[1] = new PasteToWeb2(); + pasteToWebs[1]->pageIndex = 1; + Options::instance = new Options(); + pasteToWebs[0]->ConfigureSettings(); + pasteToWebs[1]->ConfigureSettings(); + Options::instance->Load(); + hModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + hOptionsInit = HookEvent(ME_OPT_INITIALISE, Options::InitOptions); + hTabsrmmButtonPressed = NULL; + hServiceContactMenu = CreateServiceFunction(MS_PASTEIT_CONTACTMENU, ContactMenuService); + contactWindows = new std::map(); + return 0; +} + +extern "C" int __declspec(dllexport) Unload(void) +{ + UnhookEvent(hModulesLoaded); + UnhookEvent(hPrebuildContactMenu); + UnhookEvent(hOptionsInit); + if(hWindowEvent != NULL) + { + UnhookEvent(hWindowEvent); + } + DestroyServiceFunction(hServiceContactMenu); + Netlib_CloseHandle(g_hNetlibUser); + if(hTabsrmmButtonPressed != NULL) + { + UnhookEvent(hTabsrmmButtonPressed); + } + for(int i=0; i < PasteToWeb::pages; ++i) + { + if(pasteToWebs[i] != NULL) + { + delete pasteToWebs[i]; + pasteToWebs[i] = NULL; + } + } + if(Options::instance != NULL) + { + delete Options::instance; + Options::instance = NULL; + } + + delete contactWindows; + return 0; +} diff --git a/plugins/PasteIt/src/PasteToWeb.cpp b/plugins/PasteIt/src/PasteToWeb.cpp new file mode 100644 index 0000000000..a7cc9a3b5f --- /dev/null +++ b/plugins/PasteIt/src/PasteToWeb.cpp @@ -0,0 +1,577 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "StdAfx.h" +#include "PasteToWeb.h" +#include "Options.h" +#include "resource.h" + +extern HINSTANCE hInst; + +PasteToWeb::PasteToWeb() +{ +} + + +PasteToWeb::~PasteToWeb() +{ +} + +struct FromClipboardData +{ + std::wstring content; + int page; + std::wstring format; +}; + +struct FromFileData +{ + char* content; + int contentLen; + wchar_t* contentW; + UINT codepage; + std::wstring *fileName; + int page; + std::wstring format; + bool sendFileName; +}; + +INT_PTR CALLBACK DlgProcFromClipboard(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + FromClipboardData* data = (FromClipboardData*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + int ts = 4; + Edit_SetTabStops(GetDlgItem(hwndDlg, IDC_CLIPBOARD_DATA), 1, &ts); + SetDlgItemText(hwndDlg, IDC_CLIPBOARD_DATA, data->content.c_str()); + int sel = 0; + int i = 0; + std::wstring &defFormat = Options::instance->webOptions[data->page]->defFormatId; + HWND cb = GetDlgItem(hwndDlg, IDC_FORMAT); + for(std::list::iterator it = Options::instance->webOptions[data->page]->formats.begin(); it != Options::instance->webOptions[data->page]->formats.end(); ++it) + { + ComboBox_AddString(cb, it->name.c_str()); + if(it->id == defFormat) + sel = i; + ++i; + } + if(!Options::instance->webOptions[data->page]->formats.empty()) + { + ComboBox_SetCurSel(cb, sel); + } + return TRUE; + } + case WM_COMMAND: + { + if (HIWORD(wParam) == BN_CLICKED) + { + if (LOWORD(wParam) == IDOK) + { + FromClipboardData *clipboardData = (FromClipboardData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT)); + for(std::list::iterator it = Options::instance->webOptions[clipboardData->page]->formats.begin(); it != Options::instance->webOptions[clipboardData->page]->formats.end(); ++it) + { + if(sel-- <= 0) + { + clipboardData->format = it->id; + break; + } + } + + EndDialog(hwndDlg, IDC_BTN_OK); + } + else if (LOWORD(wParam) == IDCANCEL) + { + EndDialog(hwndDlg, IDCANCEL); + } + } + + break; + } + } + + return FALSE; +} + +void RecodeDlg(HWND hwndDlg) +{ + ShowWindow(GetDlgItem(hwndDlg,IDC_RECODE),SW_HIDE); + FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + unsigned int cp = Options::GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), false, fromFileData->codepage); + mir_free(fromFileData->contentW); + int cbLen = 0; + if(cp == 1200 || cp == 1201) + { + // UTF-16 + cbLen = fromFileData->contentLen / 2; + } + else + { + cbLen = MultiByteToWideChar( cp, 0, fromFileData->content, fromFileData->contentLen, NULL, 0 ); + } + + fromFileData->contentW = ( wchar_t* )mir_alloc( sizeof( wchar_t )*(cbLen+1)); + if ( fromFileData->contentW != NULL ) + { + if(cp == 1200) + { + memcpy_s(fromFileData->contentW, sizeof( wchar_t )*(cbLen+1), fromFileData->content, sizeof( wchar_t )*cbLen); + } + else if(cp == 1201) + { + for(int i = 0 ; i < cbLen; ++i) + { + fromFileData->contentW[i] = ((unsigned char)fromFileData->content[i*2] << 8) | (unsigned char)fromFileData->content[i*2 + 1]; + } + } + else + { + MultiByteToWideChar( cp, 0, fromFileData->content, fromFileData->contentLen, fromFileData->contentW, cbLen ); + } + + fromFileData->contentW[ cbLen ] = 0; + SetDlgItemText(hwndDlg, IDC_FILE_DATA, fromFileData->contentW); + } + else + { + SetDlgItemText(hwndDlg, IDC_FILE_DATA, _T("")); + } + + fromFileData->codepage = cp; +} + +INT_PTR CALLBACK DlgProcFromFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + FromFileData *fromFileData = (FromFileData*)lParam; + int ts = 4; + Edit_SetTabStops(GetDlgItem(hwndDlg, IDC_FILE_DATA), 1, &ts); + SetDlgItemText(hwndDlg, IDC_FILE_DATA, fromFileData->contentW); + SetDlgItemText(hwndDlg, IDC_FILE_PATH, fromFileData->fileName->c_str()); + Options::InitCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), fromFileData->codepage); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + ShowWindow(GetDlgItem(hwndDlg,IDC_RECODE),SW_HIDE); + + int sel = 0; + int i = 0; + std::wstring &defFormat = Options::instance->webOptions[fromFileData->page]->defFormatId; + HWND cb = GetDlgItem(hwndDlg, IDC_FORMAT); + for(std::list::iterator it = Options::instance->webOptions[fromFileData->page]->formats.begin(); it != Options::instance->webOptions[fromFileData->page]->formats.end(); ++it) + { + ComboBox_AddString(cb, it->name.c_str()); + if(it->id == defFormat) + sel = i; + ++i; + } + if(!Options::instance->webOptions[fromFileData->page]->formats.empty()) + { + ComboBox_SetCurSel(cb, sel); + } + + if(Options::instance->webOptions[fromFileData->page]->isSendFileName) + { + bool sendFileName = Options::instance->webOptions[fromFileData->page]->sendFileName; + CheckDlgButton(hwndDlg, IDC_AUTOFORMAT, sendFileName ? 1 : 0); + Button_Enable(GetDlgItem(hwndDlg, IDC_FORMAT), sendFileName ? 0 : 1); + Button_Enable(GetDlgItem(hwndDlg, IDC_FORMATTEXT), sendFileName ? 0 : 1); + } + else + Button_Enable(GetDlgItem(hwndDlg, IDC_AUTOFORMAT), FALSE); + return TRUE; + } + case WM_COMMAND: + { + if (HIWORD(wParam) == BN_CLICKED) + { + if (LOWORD(wParam) == IDOK) + { + FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT)); + for(std::list::iterator it = Options::instance->webOptions[fromFileData->page]->formats.begin(); it != Options::instance->webOptions[fromFileData->page]->formats.end(); ++it) + { + if(sel-- <= 0) + { + fromFileData->format = it->id; + break; + } + } + + if(Options::instance->webOptions[fromFileData->page]->isSendFileName) + fromFileData->sendFileName = IsDlgButtonChecked(hwndDlg, IDC_AUTOFORMAT) ? true : false; + else + fromFileData->sendFileName = false; + + EndDialog(hwndDlg, IDC_BTN_OK); + } + else if (LOWORD(wParam) == IDCANCEL) + { + EndDialog(hwndDlg, IDCANCEL); + } + else if(LOWORD(wParam) == IDC_RECODE) + { + RecodeDlg(hwndDlg); + } + else if(LOWORD(wParam) == IDC_AUTOFORMAT) + { + UINT sendFileName = IsDlgButtonChecked(hwndDlg, IDC_AUTOFORMAT); + Button_Enable(GetDlgItem(hwndDlg, IDC_FORMAT), sendFileName ? 0 : 1); + Button_Enable(GetDlgItem(hwndDlg, IDC_FORMATTEXT), sendFileName ? 0 : 1); + } + } + else if(LOWORD(wParam) == IDC_CODEPAGE) + { + if(HIWORD(wParam) == CBN_SELCHANGE) + { + RecodeDlg(hwndDlg); + } + else if(HIWORD(wParam) == CBN_EDITCHANGE) + { + ShowWindow(GetDlgItem(hwndDlg,IDC_RECODE),SW_SHOW); + } + else if(HIWORD(wParam) == CBN_KILLFOCUS) + { + FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + Options::GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), true, fromFileData->codepage); + } + } + + break; + } + } + + return FALSE; +} + +void PasteToWeb::FromClipboard() +{ + szFileLink[0] = 0; + error = NULL; + std::wstring str; + BOOL isFile = 0; + if(OpenClipboard(NULL)) + { + HANDLE obj = GetClipboardData(CF_UNICODETEXT); + if(obj != NULL) + { + LPCWSTR wStr = (LPCWSTR)GlobalLock(obj); + str.append(wStr, wStr + wcslen(wStr)); + GlobalUnlock(obj); + // Sometimes clipboard CF_UNICODETEXT format returns only 2 characters, + // to fix this I check if CF_TEXT contains more characters, + // if this is true, this mean that CF_UNICODETEXT is invalid. + obj = GetClipboardData(CF_TEXT); + if(obj != NULL) + { + LPCSTR cStr = (LPCSTR)GlobalLock(obj); + if(strlen(cStr) > str.length()) + { + str = L""; + LPWSTR wStr = mir_a2u_cp(cStr, CP_ACP); + str.append(wStr, wStr + wcslen(wStr)); + mir_free(wStr); + } + GlobalUnlock(obj); + } + } + else + { + obj = GetClipboardData(CF_TEXT); + if(obj != NULL) + { + LPCSTR cStr = (LPCSTR)GlobalLock(obj); + LPWSTR wStr = mir_a2u_cp(cStr, CP_ACP); + str.append(wStr, wStr + wcslen(wStr)); + mir_free(wStr); + GlobalUnlock(obj); + } + else + { + obj = GetClipboardData(CF_HDROP); + if(obj != NULL) + { + LPDROPFILES df = (LPDROPFILES) GlobalLock(obj); + isFile = 1; + if(df->fWide) + { + // Unicode + WCHAR* file = (WCHAR*)((BYTE*)obj + df->pFiles); + size_t len = wcslen(file); + if(*(file + len + 1) == L'\0') + { + str.append(file, file + len); + } + else + { + error = TranslateT("You can only paste 1 file"); + } + } + else + { + // ANSI + char* file = (char*)obj + df->pFiles; + size_t len = strlen(file); + if(*(file + len + 1) == '\0') + { + LPWSTR wStr = mir_a2u_cp(file, CP_ACP); + str.append(wStr, wStr + wcslen(wStr)); + mir_free(wStr); + } + else + { + error = TranslateT("You can only paste 1 file"); + } + } + GlobalUnlock(obj); + } + } + } + + CloseClipboard(); + } + + if(str.length() > 0) + { + if(isFile) + FromFile(str); + else + { + FromClipboardData data; + data.content = str; + data.page = pageIndex; + if (Options::instance->confDlg && DialogBoxParam (hInst, MAKEINTRESOURCE(IDD_DLG_FROM_CLIPBOARD), 0, DlgProcFromClipboard, (LPARAM)&data) != IDC_BTN_OK) + return; + + SendToServer(str, L"", data.format); + } + } + else if(error == NULL) + { + error = TranslateT("Cannot get data from clipboard"); + } +} + +void PasteToWeb::FromFile(std::wstring file) +{ + error = NULL; + szFileLink[0] = 0; + HANDLE hFile = CreateFile(file.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + FromFileData fromFileData; + fromFileData.content = NULL; + fromFileData.contentLen = 0; + fromFileData.fileName = &file; + if(hFile != INVALID_HANDLE_VALUE) + { + LARGE_INTEGER fileSize; + if(GetFileSizeEx(hFile, &fileSize)) + { + if(fileSize.QuadPart <= 10485760LL) + { + if(fileSize.QuadPart > 512000LL) + { + _stprintf_s(bufErr, 1024, TranslateT("File size is %dKB, do you realy want to paste such large file?"), fileSize.LowPart / 1024); + if(MessageBox(NULL, bufErr, TranslateT("Are You sure?"), MB_YESNO | MB_ICONQUESTION) != IDYES) + { + CloseHandle(hFile); + return; + } + } + DWORD readed; + fromFileData.contentLen = fileSize.LowPart; + fromFileData.content = (char*)mir_alloc(fromFileData.contentLen); + if(!ReadFile(hFile, fromFileData.content, fromFileData.contentLen, &readed, NULL)) + { + mir_free(fromFileData.content); + fromFileData.content = NULL; + fromFileData.contentLen = 0; + _stprintf_s(bufErr, 1024, TranslateT("Cannot read file '%s'"), file.c_str()); + error = bufErr; + } + } + else + { + error = TranslateT("File size is larger then 10MB, cannot be send"); + } + } + + CloseHandle(hFile); + } + else + { + _stprintf_s(bufErr, 1024, TranslateT("Cannot open file '%s'"), file.c_str()); + error = bufErr; + } + + if(fromFileData.content != NULL) + { + int cbLen = 0; + bool isDefTranslation = true; + if(Options::instance->autoUTF) + { + isDefTranslation = false; + fromFileData.codepage = CP_UTF8; + cbLen = MultiByteToWideChar( fromFileData.codepage, MB_ERR_INVALID_CHARS, fromFileData.content, fromFileData.contentLen, NULL, 0 ); + if(cbLen == 0) + { + int errorN = GetLastError(); + if(errorN == ERROR_NO_UNICODE_TRANSLATION) + { + isDefTranslation = true; + } + } + } + + if(isDefTranslation) + { + fromFileData.codepage = Options::instance->codepage; + if(fromFileData.codepage == 1200 || fromFileData.codepage == 1201) + { + // UTF-16 + cbLen = fromFileData.contentLen / 2; + } + else + { + cbLen = MultiByteToWideChar( fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, NULL, 0 ); + } + } + + if(cbLen > 0) + { + fromFileData.contentW = ( wchar_t* )mir_alloc( sizeof( wchar_t )*(cbLen+1)); + if ( fromFileData.contentW != NULL ) + { + if(fromFileData.codepage == 1200) + { + memcpy_s(fromFileData.contentW, sizeof( wchar_t )*(cbLen+1), fromFileData.content, sizeof( wchar_t )*cbLen); + } + else if(fromFileData.codepage == 1201) + { + for(int i = 0 ; i < cbLen; ++i) + { + fromFileData.contentW[i] = (fromFileData.content[i*2] << 8) | fromFileData.content[i*2 + 1]; + } + } + else + { + MultiByteToWideChar( fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, fromFileData.contentW, cbLen ); + } + + fromFileData.contentW[ cbLen ] = 0; + fromFileData.page = pageIndex; + if (!Options::instance->confDlg || DialogBoxParam (hInst, MAKEINTRESOURCE(IDD_DLG_FROM_FILE), 0, DlgProcFromFile, (LPARAM)&fromFileData) == IDC_BTN_OK) + { + std::wstring fileName; + std::wstring::size_type pos1 = file.find_last_of(L'\\'); + std::wstring::size_type pos2 = file.find_last_of(L'/'); + if(pos2 > pos1 && pos2 < file.length()) + pos1 = pos2; + if(pos1 >= 0 && pos1 + 1 < file.length()) + fileName = file.substr(pos1 + 1); + else + fileName = file; + SendToServer(fromFileData.contentW, fromFileData.sendFileName ? fileName : L"", fromFileData.format); + } + mir_free(fromFileData.contentW); + } + } + else + { + _stprintf_s(bufErr, 1024, TranslateT("File '%s' is empty"), file.c_str()); + error = bufErr; + } + mir_free(fromFileData.content); + } +} + +extern HANDLE g_hNetlibUser; + +wchar_t* PasteToWeb::SendToWeb(char* url, std::map& headers, std::wstring content) +{ + wchar_t* resCont = NULL; + int cbLen = WideCharToMultiByte( CP_UTF8, 0, content.c_str(), -1, NULL, 0, NULL, NULL ); + char* contentBytes = ( char* )mir_alloc(cbLen); + if ( contentBytes == NULL ) + return resCont; + + WideCharToMultiByte( CP_UTF8, 0, content.c_str(), -1, contentBytes, cbLen, NULL, NULL ); + --cbLen; + + int nHeaders = 0; + for(std::map::iterator it = headers.begin(); it != headers.end(); ++it) + { + ++nHeaders; + } + + NETLIBHTTPREQUEST nlhr={0}; + NETLIBHTTPHEADER* httpHeaders = new NETLIBHTTPHEADER[nHeaders]; + nlhr.cbSize=sizeof(nlhr); + nlhr.requestType=REQUEST_POST; + nlhr.flags=NLHRF_NODUMPSEND|NLHRF_DUMPASTEXT|NLHPIF_HTTP11; + nlhr.szUrl=url; + nlhr.headers = httpHeaders; + nlhr.pData = contentBytes; + nlhr.dataLength = cbLen; + nHeaders = 0; + std::list mallBuf; + for(std::map::iterator it = headers.begin(); it != headers.end(); ++it) + { + char* b1 = new char[it->first.length() + 1]; + char* b2 = new char[it->second.length() + 1]; + strcpy_s(b1, it->first.length() + 1, it->first.c_str()); + strcpy_s(b2, it->second.length() + 1, it->second.c_str()); + httpHeaders[nHeaders].szName = b1; + httpHeaders[nHeaders].szValue = b2; + mallBuf.push_back(b1); + mallBuf.push_back(b2); + ++nHeaders; + } + + nlhr.headersCount = nHeaders; + NETLIBHTTPREQUEST* nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)g_hNetlibUser,(LPARAM)&nlhr); + if(nlhrReply != NULL) + { + if(nlhrReply->resultCode == 200) + { + int resLen = MultiByteToWideChar(CP_UTF8, 0, nlhrReply->pData, nlhrReply->dataLength, NULL, 0); + ++resLen; + resCont = ( wchar_t* )mir_alloc(resLen * sizeof(wchar_t)); + if ( resCont != NULL ) + { + resLen = MultiByteToWideChar( CP_UTF8, 0, nlhrReply->pData, nlhrReply->dataLength, resCont, resLen); + resCont[resLen] = 0; + } + } + + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)nlhrReply); + } + delete httpHeaders; + for(std::list::iterator it = mallBuf.begin(); it != mallBuf.end(); ++it) + { + delete *it; + } + + mir_free(contentBytes); + return resCont; +} diff --git a/plugins/PasteIt/src/PasteToWeb.h b/plugins/PasteIt/src/PasteToWeb.h new file mode 100644 index 0000000000..51e2141790 --- /dev/null +++ b/plugins/PasteIt/src/PasteToWeb.h @@ -0,0 +1,47 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +struct PasteFormat +{ + std::wstring id; + std::wstring name; +}; + +class PasteToWeb +{ +protected: + virtual void SendToServer(std::wstring str, std::wstring fileName, std::wstring format) = 0; + wchar_t* SendToWeb(char* url, std::map& headers, std::wstring content); + PasteToWeb(); + TCHAR bufErr[1024]; +public: + virtual ~PasteToWeb(); + char szFileLink[256]; + TCHAR* error; + void FromClipboard(); + void FromFile(std::wstring file); + virtual TCHAR* GetName() = 0; + virtual void ConfigureSettings() = 0; + int pageIndex; + virtual std::list GetFormats() = 0; + virtual std::list GetDefFormats() = 0; + static const int pages = 2; +}; + diff --git a/plugins/PasteIt/src/PasteToWeb1.cpp b/plugins/PasteIt/src/PasteToWeb1.cpp new file mode 100644 index 0000000000..bbdc2e1ba5 --- /dev/null +++ b/plugins/PasteIt/src/PasteToWeb1.cpp @@ -0,0 +1,393 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "StdAfx.h" +#include "PasteToWeb1.h" +#include "Options.h" + +PasteFormat PasteToWeb1::formats[] = +{ + {L"4cs", L"4CS"}, + {L"6502acme", L"6502 ACME Cross Assembler"}, + {L"6502kickass", L"6502 Kick Assembler"}, + {L"6502tasm", L"6502 TASM/64TASS"}, + {L"abap", L"ABAP"}, + {L"actionscript", L"ActionScript"}, + {L"actionscript3", L"ActionScript 3"}, + {L"ada", L"Ada"}, + {L"algol68", L"ALGOL 68"}, + {L"apache", L"Apache Log"}, + {L"applescript", L"AppleScript"}, + {L"apt_sources", L"APT Sources"}, + {L"asm", L"ASM (NASM)"}, + {L"asp", L"ASP"}, + {L"autoconf", L"autoconf"}, + {L"autohotkey", L"Autohotkey"}, + {L"autoit", L"AutoIt"}, + {L"avisynth", L"Avisynth"}, + {L"awk", L"Awk"}, + {L"bascomavr", L"BASCOM AVR"}, + {L"bash", L"Bash"}, + {L"basic4gl", L"Basic4GL"}, + {L"bibtex", L"BibTeX"}, + {L"blitzbasic", L"Blitz Basic"}, + {L"bnf", L"BNF"}, + {L"boo", L"BOO"}, + {L"bf", L"BrainFuck"}, + {L"c", L"C"}, + {L"c_mac", L"C for Macs"}, + {L"cil", L"C Intermediate Language"}, + {L"csharp", L"C#"}, + {L"cpp", L"C++"}, + {L"cpp-qt", L"C++ (with QT extensions)"}, + {L"c_loadrunner", L"C: Loadrunner"}, + {L"caddcl", L"CAD DCL"}, + {L"cadlisp", L"CAD Lisp"}, + {L"cfdg", L"CFDG"}, + {L"chaiscript", L"ChaiScript"}, + {L"clojure", L"Clojure"}, + {L"klonec", L"Clone C"}, + {L"klonecpp", L"Clone C++"}, + {L"cmake", L"CMake"}, + {L"cobol", L"COBOL"}, + {L"coffeescript", L"CoffeeScript"}, + {L"cfm", L"ColdFusion"}, + {L"css", L"CSS"}, + {L"cuesheet", L"Cuesheet"}, + {L"d", L"D"}, + {L"dcs", L"DCS"}, + {L"delphi", L"Delphi"}, + {L"oxygene", L"Delphi Prism (Oxygene)"}, + {L"diff", L"Diff"}, + {L"div", L"DIV"}, + {L"dos", L"DOS"}, + {L"dot", L"DOT"}, + {L"e", L"E"}, + {L"ecmascript", L"ECMAScript"}, + {L"eiffel", L"Eiffel"}, + {L"email", L"Email"}, + {L"epc", L"EPC"}, + {L"erlang", L"Erlang"}, + {L"fsharp", L"F#"}, + {L"falcon", L"Falcon"}, + {L"fo", L"FO Language"}, + {L"f1", L"Formula One"}, + {L"fortran", L"Fortran"}, + {L"freebasic", L"FreeBasic"}, + {L"gambas", L"GAMBAS"}, + {L"gml", L"Game Maker"}, + {L"gdb", L"GDB"}, + {L"genero", L"Genero"}, + {L"genie", L"Genie"}, + {L"gettext", L"GetText"}, + {L"go", L"Go"}, + {L"groovy", L"Groovy"}, + {L"gwbasic", L"GwBasic"}, + {L"haskell", L"Haskell"}, + {L"hicest", L"HicEst"}, + {L"hq9plus", L"HQ9 Plus"}, + {L"html4strict", L"HTML"}, + {L"html5", L"HTML 5"}, + {L"icon", L"Icon"}, + {L"idl", L"IDL"}, + {L"ini", L"INI file"}, + {L"inno", L"Inno Script"}, + {L"intercal", L"INTERCAL"}, + {L"io", L"IO"}, + {L"j", L"J"}, + {L"java", L"Java"}, + {L"java5", L"Java 5"}, + {L"javascript", L"JavaScript"}, + {L"jquery", L"jQuery"}, + {L"kixtart", L"KiXtart"}, + {L"latex", L"Latex"}, + {L"lb", L"Liberty BASIC"}, + {L"lsl2", L"Linden Scripting"}, + {L"lisp", L"Lisp"}, + {L"llvm", L"LLVM"}, + {L"locobasic", L"Loco Basic"}, + {L"logtalk", L"Logtalk"}, + {L"lolcode", L"LOL Code"}, + {L"lotusformulas", L"Lotus Formulas"}, + {L"lotusscript", L"Lotus Script"}, + {L"lscript", L"LScript"}, + {L"lua", L"Lua"}, + {L"m68k", L"M68000 Assembler"}, + {L"magiksf", L"MagikSF"}, + {L"make", L"Make"}, + {L"mapbasic", L"MapBasic"}, + {L"matlab", L"MatLab"}, + {L"mirc", L"mIRC"}, + {L"mmix", L"MIX Assembler"}, + {L"modula2", L"Modula 2"}, + {L"modula3", L"Modula 3"}, + {L"68000devpac", L"Motorola 68000 HiSoft Dev"}, + {L"mpasm", L"MPASM"}, + {L"mxml", L"MXML"}, + {L"mysql", L"MySQL"}, + {L"newlisp", L"newLISP"}, + {L"text", L"None"}, + {L"nsis", L"NullSoft Installer"}, + {L"oberon2", L"Oberon 2"}, + {L"objeck", L"Objeck Programming Langua"}, + {L"objc", L"Objective C"}, + {L"ocaml-brief", L"OCalm Brief"}, + {L"ocaml", L"OCaml"}, + {L"pf", L"OpenBSD PACKET FILTER"}, + {L"glsl", L"OpenGL Shading"}, + {L"oobas", L"Openoffice BASIC"}, + {L"oracle11", L"Oracle 11"}, + {L"oracle8", L"Oracle 8"}, + {L"oz", L"Oz"}, + {L"pascal", L"Pascal"}, + {L"pawn", L"PAWN"}, + {L"pcre", L"PCRE"}, + {L"per", L"Per"}, + {L"perl", L"Perl"}, + {L"perl6", L"Perl 6"}, + {L"php", L"PHP"}, + {L"php-brief", L"PHP Brief"}, + {L"pic16", L"Pic 16"}, + {L"pike", L"Pike"}, + {L"pixelbender", L"Pixel Bender"}, + {L"plsql", L"PL/SQL"}, + {L"postgresql", L"PostgreSQL"}, + {L"povray", L"POV-Ray"}, + {L"powershell", L"Power Shell"}, + {L"powerbuilder", L"PowerBuilder"}, + {L"proftpd", L"ProFTPd"}, + {L"progress", L"Progress"}, + {L"prolog", L"Prolog"}, + {L"properties", L"Properties"}, + {L"providex", L"ProvideX"}, + {L"purebasic", L"PureBasic"}, + {L"pycon", L"PyCon"}, + {L"python", L"Python"}, + {L"q", L"q/kdb+"}, + {L"qbasic", L"QBasic"}, + {L"rsplus", L"R"}, + {L"rails", L"Rails"}, + {L"rebol", L"REBOL"}, + {L"reg", L"REG"}, + {L"robots", L"Robots"}, + {L"rpmspec", L"RPM Spec"}, + {L"ruby", L"Ruby"}, + {L"gnuplot", L"Ruby Gnuplot"}, + {L"sas", L"SAS"}, + {L"scala", L"Scala"}, + {L"scheme", L"Scheme"}, + {L"scilab", L"Scilab"}, + {L"sdlbasic", L"SdlBasic"}, + {L"smalltalk", L"Smalltalk"}, + {L"smarty", L"Smarty"}, + {L"sql", L"SQL"}, + {L"systemverilog", L"SystemVerilog"}, + {L"tsql", L"T-SQL"}, + {L"tcl", L"TCL"}, + {L"teraterm", L"Tera Term"}, + {L"thinbasic", L"thinBasic"}, + {L"typoscript", L"TypoScript"}, + {L"unicon", L"Unicon"}, + {L"uscript", L"UnrealScript"}, + {L"vala", L"Vala"}, + {L"vbnet", L"VB.NET"}, + {L"verilog", L"VeriLog"}, + {L"vhdl", L"VHDL"}, + {L"vim", L"VIM"}, + {L"visualprolog", L"Visual Pro Log"}, + {L"vb", L"VisualBasic"}, + {L"visualfoxpro", L"VisualFoxPro"}, + {L"whitespace", L"WhiteSpace"}, + {L"whois", L"WHOIS"}, + {L"winbatch", L"Win Batch"}, + {L"xbasic", L"XBasic"}, + {L"xml", L"XML"}, + {L"xorg_conf", L"Xorg Config"}, + {L"xpp", L"XPP"}, + {L"yaml", L"YAML"}, + {L"z80", L"Z80 Assembler"}, + {L"zxbasic", L"ZXBasic"}, +}; + +PasteFormat PasteToWeb1::defFormats[] = +{ + {L"text", L"None"}, + {L"xml", L"XML"}, + {L"html4strict", L"HTML"}, + {L"html5", L"HTML 5"}, + {L"javascript", L"JavaScript"}, + {L"php", L"PHP"}, + {L"c", L"C"}, + {L"csharp", L"C#"}, + {L"cpp", L"C++"}, + {L"java", L"Java"}, + {L"java5", L"Java 5"}, + {L"ini", L"INI file"}, + {L"css", L"CSS"}, + {L"sql", L"SQL"}, + {L"asm", L"ASM (NASM)"}, + {L"asp", L"ASP"}, + {L"caddcl", L"CAD DCL"}, + {L"cadlisp", L"CAD Lisp"}, + {L"delphi", L"Delphi"}, + {L"diff", L"Diff"}, + {L"jquery", L"jQuery"}, + {L"latex", L"Latex"}, + {L"pascal", L"Pascal"}, + {L"perl", L"Perl"}, + {L"perl6", L"Perl 6"}, + {L"python", L"Python"}, + {L"vbnet", L"VB.NET"}, + {L"vb", L"VisualBasic"}, +}; + +PasteToWeb1::PasteToWeb1() +{ +} + + +PasteToWeb1::~PasteToWeb1() +{ +} + +void PasteToWeb1::SendToServer(std::wstring str, std::wstring fileName, std::wstring format) +{ + std::map headers; + headers["Content-Type"] = "application/x-www-form-urlencoded"; + std::wstring content = _T("api_option=paste&api_paste_private="); + content += Options::instance->webOptions[pageIndex]->publicPaste ? _T("0") : _T("1"); + content += _T("&api_paste_expire_date="); + content += Options::instance->webOptions[pageIndex]->combo1.empty() ? _T("1M") : Options::instance->webOptions[pageIndex]->combo1; + content += _T("&api_dev_key=dcba056bf9cc71729fdad76dddcb0dcd&api_paste_format="); + content += format; + if(!Options::instance->webOptions[pageIndex]->pastebinUserKey.empty()) + { + content += _T("&api_user_key="); + content += Options::instance->webOptions[pageIndex]->pastebinUserKey; + } + content += _T("&api_paste_code="); + for(std::wstring::iterator it = str.begin(); it != str.end(); ++it) + { + if(*it == L'%') + { + content += L"%25"; + } + else if(*it ==L'&') + { + content += L"%26"; + } + else if(*it ==L'=') + { + content += L"%3D"; + } + else + { + content += *it; + } + } + + wchar_t* resCont = SendToWeb("http://pastebin.com/api/api_post.php", headers, content); + if(resCont != NULL) + { + if(memcmp(L"Bad API request, ", resCont, 17 * sizeof(wchar_t)) == 0) + { + _stprintf_s(bufErr, 1024, TranslateT("Error during sending text to web page: %s"), resCont + 17); + error = bufErr; + } + else + { + char* s = mir_u2a_cp(resCont, CP_ACP); + strcpy_s(szFileLink, 256, s); + mir_free(s); + } + mir_free(resCont); + } + else + { + error = TranslateT("Error during sending text to web page"); + } +} + +std::wstring PasteToWeb1::GetUserKey(std::wstring& user, std::wstring& password) +{ + std::map headers; + headers["Content-Type"] = "application/x-www-form-urlencoded"; + std::wstring content = _T("api_user_name="); + content += user; + content += _T("&api_user_password="); + content += password; + content += _T("&api_dev_key=dcba056bf9cc71729fdad76dddcb0dcd"); + wchar_t* resCont = SendToWeb("http://pastebin.com/api/api_login.php", headers, content); + std::wstring toRet; + if(resCont != NULL) + { + if(memcmp(L"Bad API request, ", resCont, 17 * sizeof(wchar_t)) == 0) + { + _stprintf_s(bufErr, 1024, TranslateT("Error during getting user key from web page: %s"), resCont + 17); + MessageBox(NULL, bufErr, TranslateT("Error"), MB_OK | MB_ICONERROR); + } + else + toRet = resCont; + mir_free(resCont); + } + + return toRet; +} + +std::list PasteToWeb1::GetFormats() +{ + int count = sizeof(formats) / sizeof(formats[0]); + std::list ret(formats, formats + count); + + return ret; +} + +std::list PasteToWeb1::GetDefFormats() +{ + int count = sizeof(defFormats) / sizeof(defFormats[0]); + std::list ret(defFormats, defFormats + count); + + return ret; +} + +void PasteToWeb1::ConfigureSettings() +{ + Options::instance->webOptions[pageIndex]->isSendFileName = false; + Options::instance->webOptions[pageIndex]->isPublicPaste = true; + Options::instance->webOptions[pageIndex]->isCombo1 = true; + Options::instance->webOptions[pageIndex]->combo1Desc = TranslateT("Paste expire date"); + PasteFormat pf; + pf.id = L"N"; + pf.name = TranslateT("Never"); + Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf); + pf.id = L"10M"; + pf.name = TranslateT("10 minutes"); + Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf); + pf.id = L"1H"; + pf.name = TranslateT("1 hour"); + Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf); + pf.id = L"1D"; + pf.name = TranslateT("1 day"); + Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf); + pf.id = L"1M"; + pf.name = TranslateT("1 month"); + Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf); + Options::instance->webOptions[pageIndex]->combo1 = L"1M"; + Options::instance->webOptions[pageIndex]->isPastebin = true; +} + diff --git a/plugins/PasteIt/src/PasteToWeb1.h b/plugins/PasteIt/src/PasteToWeb1.h new file mode 100644 index 0000000000..b1611855d6 --- /dev/null +++ b/plugins/PasteIt/src/PasteToWeb1.h @@ -0,0 +1,40 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once +#include "pastetoweb.h" +class PasteToWeb1 : + public PasteToWeb +{ +protected: + virtual void SendToServer(std::wstring str, std::wstring fileName, std::wstring format); + static PasteFormat formats[]; + static PasteFormat defFormats[]; +public: + PasteToWeb1(); + virtual ~PasteToWeb1(); + virtual TCHAR* GetName() + { + return _T("pastebin.com"); + } + virtual void ConfigureSettings(); + virtual std::list GetFormats(); + virtual std::list GetDefFormats(); + std::wstring GetUserKey(std::wstring& user, std::wstring& password); +}; + diff --git a/plugins/PasteIt/src/PasteToWeb2.cpp b/plugins/PasteIt/src/PasteToWeb2.cpp new file mode 100644 index 0000000000..c2edbddeef --- /dev/null +++ b/plugins/PasteIt/src/PasteToWeb2.cpp @@ -0,0 +1,247 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "StdAfx.h" +#include "PasteToWeb2.h" + +PasteFormat PasteToWeb2::defFormats[] = +{ + {L"text", L"Text"}, + {L"xml", L"XML"}, + {L"html", L"HTML"}, + {L"js", L"JavaScript"}, + {L"php", L"PHP"}, + {L"c", L"C"}, + {L"csharp", L"C#"}, + {L"cpp", L"C++"}, + {L"java", L"Java"}, + {L"ini", L"INI"}, + {L"css", L"CSS"}, + {L"sql", L"SQL"}, + {L"nasm", L"NASM"}, + {L"delphi", L"Delphi"}, + {L"diff", L"Diff"}, + {L"tex", L"TeX"}, + {L"perl", L"Perl"}, + {L"python", L"Python"}, + {L"vb.net", L"VB.net"} +}; + +PasteToWeb2::PasteToWeb2() +{ +} + + +PasteToWeb2::~PasteToWeb2() +{ +} + +void PasteToWeb2::SendToServer(std::wstring str, std::wstring fileName, std::wstring format) +{ + std::map headers; + headers["Content-Type"] = "text/xml"; + std::wstring content = _T("\r\ncreate_paste"); + if(fileName == L"") + { + content += format; + content += _T(""); + } + else + { + content += _T(""); + } + for(std::wstring::iterator it = str.begin(); it != str.end(); ++it) + { + if(*it == L'&') + { + content += L"&"; + } + else if(*it ==L'<') + { + content += L"<"; + } + else + { + content += *it; + } + } + + content += _T(""); + if(fileName != L"") + { + for(std::wstring::iterator it = fileName.begin(); it != fileName.end(); ++it) + { + if(*it == L'&') + { + content += L"&"; + } + else if(*it ==L'<') + { + content += L"<"; + } + else + { + content += *it; + } + } + } + content += _T("1.5"); + + wchar_t* resCont = SendToWeb("http://wklej.to/api/", headers, content); + error = TranslateT("Error during sending text to web page"); + if(resCont != NULL) + { + HXML hXml = xi.parseString(resCont, NULL, _T("methodResponse")); + if(hXml != NULL) + { + HXML node = xi.getChildByPath(hXml, _T("params/param/value/array/data/value/int"), 0); + if(node != NULL && !_tcscmp(xi.getText(node), _T("1"))) + { + node = xi.getChildByPath(hXml, _T("params/param/value/array/data"), 0); + if(node != NULL) + { + node = xi.getNthChild(node, _T("value"), 1); + if(node != NULL) + { + node = xi.getChildByPath(node, _T("string"), 0); + if(node != NULL) + { + char* s = mir_t2a_cp(xi.getText(node), CP_ACP); + strcpy_s(szFileLink, 256, s); + mir_free(s); + error = NULL; + } + } + } + } + xi.destroyNode(hXml); + } + mir_free(resCont); + } +} + +std::list PasteToWeb2::GetFormats() +{ + std::list ret; + + std::map headers; + headers["Content-Type"] = "text/xml"; + std::wstring content = _T("\r\ntypes"); + + wchar_t* resCont = SendToWeb("http://wklej.to/api/", headers, content); + if(resCont != NULL) + { + HXML hXml = xi.parseString(resCont, NULL, _T("methodResponse")); + if(hXml != NULL) + { + HXML node = xi.getChildByPath(hXml, _T("params/param/value/array/data/value/int"), 0); + if(node != NULL && !_tcscmp(xi.getText(node), _T("1"))) + { + node = xi.getChildByPath(hXml, _T("params/param/value/array/data"), 0); + if(node != NULL) + { + node = xi.getNthChild(node, _T("value"), 1); + if(node != NULL) + { + node = xi.getChildByPath(node, _T("string"), 0); + if(node != NULL) + { + std::wstring str = xi.getText(node); + std::wstring::size_type pos = str.find(L'\n'); + if(pos < str.length()) + { + str = str.substr(pos + 1); + } + pos = str.find(L'\n'); + if(pos < str.length()) + { + str = str.substr(pos + 1); + } + pos = str.find(L'\n'); + while(pos < str.length()) + { + std::wstring line = str.substr(0, pos); + std::wstring::size_type sep = line.find(L':'); + if(sep < line.length()) + { + PasteFormat pf; + pf.name = line.substr(0, sep); + std::wstring::size_type sep2 = line.find(L','); + if(sep2 < line.length()) + { + pf.id = line.substr(sep + 2, sep2 - sep - 2); + } + else + { + pf.id = line.substr(sep + 2); + } + ret.push_back(pf); + } + + if(pos < str.length() - 1) + { + str = str.substr(pos + 1); + } + else + { + str = L""; + } + pos = str.find(L'\n'); + } + { + std::wstring line = str; + std::wstring::size_type sep = line.find(L':'); + if(sep < line.length()) + { + PasteFormat pf; + pf.name = line.substr(0, sep); + std::wstring::size_type sep2 = line.find(L','); + if(sep2 < line.length()) + { + pf.id = line.substr(sep + 2, sep2 - sep - 2); + } + else + { + pf.id = line.substr(sep + 2); + } + ret.push_back(pf); + } + } + } + } + } + } + xi.destroyNode(hXml); + } + mir_free(resCont); + } + + return ret; +} + +std::list PasteToWeb2::GetDefFormats() +{ + int count = sizeof(defFormats) / sizeof(defFormats[0]); + std::list ret(defFormats, defFormats + count); + + return ret; +} + +void PasteToWeb2::ConfigureSettings() +{ +} diff --git a/plugins/PasteIt/src/PasteToWeb2.h b/plugins/PasteIt/src/PasteToWeb2.h new file mode 100644 index 0000000000..364c6eb4e4 --- /dev/null +++ b/plugins/PasteIt/src/PasteToWeb2.h @@ -0,0 +1,38 @@ +/* +Paste It plugin +Copyright (C) 2011 Krzysztof Kral + +This program 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 version 2 +of the License. + +This program 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once +#include "pastetoweb.h" +class PasteToWeb2 : + public PasteToWeb +{ +protected: + virtual void SendToServer(std::wstring str, std::wstring fileName, std::wstring format); + static PasteFormat defFormats[]; +public: + PasteToWeb2(); + virtual ~PasteToWeb2(); + virtual TCHAR* GetName() + { + return _T("wklej.to"); + } + virtual void ConfigureSettings(); + virtual std::list GetFormats(); + virtual std::list GetDefFormats(); +}; + diff --git a/plugins/PasteIt/src/resource.h b/plugins/PasteIt/src/resource.h new file mode 100644 index 0000000000..cbfa566679 --- /dev/null +++ b/plugins/PasteIt/src/resource.h @@ -0,0 +1,50 @@ + +#define IDD_OPT_MAIN 101 +#define IDD_DLG_FROM_CLIPBOARD 102 +#define IDD_DLG_FROM_FILE 103 +#define IDD_OPT_PAGES 104 +#define IDD_DLG_CONFIGURE 105 +#define IDD_DLG_PASTEBIN_LOGIN 106 +#define IDC_WEBLIST 1001 +#define IDC_CONFDLG 1002 +#define IDC_AUTOSEND 1003 +#define IDC_CODEPAGE 1004 +#define IDC_AUTOUTF 1005 +#define IDC_CLIPBOARD_DATA 1006 +#define IDC_BTN_OK 1007 +#define IDC_FILE_DATA 1008 +#define IDC_FILE_PATH 1009 +#define IDC_RECODE 1010 +#define IDC_WEBPAGE 1011 +#define IDC_DEFFORMAT 1012 +#define IDC_AUTOFORMAT 1013 +#define IDC_CONFIGURE 1014 +#define IDC_FORMATTING 1015 +#define IDC_RESTORE 1016 +#define IDC_DOWNLOAD 1017 +#define IDC_DELETE 1018 +#define IDC_UP 1019 +#define IDC_DOWN 1020 +#define IDC_FORMAT 1021 +#define IDC_FORMATTEXT 1022 +#define IDC_PUBLICPASTE 1023 +#define IDC_COMBO1 1024 +#define IDC_COMBO1_DESC 1025 +#define IDC_GUEST 1026 +#define IDC_PASTEBIN_KEY 1027 +#define IDC_PASTEBIN_KEY_DESC 1028 +#define IDC_PASTEBIN_LOGIN 1029 +#define IDC_PASTEBIN_USER 1031 +#define IDC_PASTEBIN_PASSWORD 1032 +#define IDI_MENU 20000 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 107 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1033 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/PasteIt/src/stdafx.h b/plugins/PasteIt/src/stdafx.h new file mode 100644 index 0000000000..2be1eff36d --- /dev/null +++ b/plugins/PasteIt/src/stdafx.h @@ -0,0 +1,42 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define MIRANDA_VER 0x0A00 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "m_msg_buttonsbar.h" diff --git a/plugins/PasteIt/src/targetver.h b/plugins/PasteIt/src/targetver.h new file mode 100644 index 0000000000..90e767bfce --- /dev/null +++ b/plugins/PasteIt/src/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/plugins/PasteIt/src/version.h b/plugins/PasteIt/src/version.h new file mode 100644 index 0000000000..e7d016c0a4 --- /dev/null +++ b/plugins/PasteIt/src/version.h @@ -0,0 +1,20 @@ +#define __MAJOR_VERSION 1 +#define __MINOR_VERSION 0 +#define __RELEASE_NUM 0 +#define __BUILD_NUM 3 + +#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM +#define __FILEVERSION_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM + +#define __STRINGIFY_IMPL(x) #x +#define __STRINGIFY(x) __STRINGIFY_IMPL(x) +#define __VERSION_STRING __STRINGIFY(__FILEVERSION_DOTS) + +#define __PLUGIN_NAME "Paste It" +#define __INTERNAL_NAME "PasteIt" +#define __FILENAME "PasteIt.dll" +#define __DESCRIPTION "Uploads the text to web page and sends the URL to your friends." +#define __AUTHOR "Krzysztof Kral" +#define __AUTHOREMAIL "programista@poczta.of.pl" +#define __AUTHORWEB "http://programista.free.of.pl/miranda/" +#define __COPYRIGHT "Copyright (c) 2011 KrzysztofKral" -- cgit v1.2.3