summaryrefslogtreecommitdiff
path: root/src/mir_core
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-06-21 19:09:56 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-06-21 19:09:56 +0000
commitba456be50d3b780e4accf075ba78d5badf282b05 (patch)
treea1e4a2df606b21f814306f7c0bfdef15d6de419b /src/mir_core
parenta08db3aa08808c6adec9891d429f262126faca80 (diff)
MS_UTIL_OPENURL -> mir_core::Utils_OpenUrl
git-svn-id: http://svn.miranda-ng.org/main/trunk@14306 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_core')
-rw-r--r--src/mir_core/src/mir_core.def2
-rw-r--r--src/mir_core/src/mir_core64.def2
-rw-r--r--src/mir_core/src/openurl.cpp78
3 files changed, 82 insertions, 0 deletions
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def
index d12bbf2897..fed657fd09 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -971,3 +971,5 @@ TimeZone_ToStringW @1128
TimeZone_UtcToLocal @1129
Utils_ResizeDialog @1130
Utils_GetRandom @1131
+Utils_OpenUrl @1132
+Utils_OpenUrlW @1133
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index 3cd65aa139..af4a9a45d7 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -971,3 +971,5 @@ TimeZone_ToStringW @1128
TimeZone_UtcToLocal @1129
Utils_ResizeDialog @1130
Utils_GetRandom @1131
+Utils_OpenUrl @1132
+Utils_OpenUrlW @1133
diff --git a/src/mir_core/src/openurl.cpp b/src/mir_core/src/openurl.cpp
new file mode 100644
index 0000000000..00b2813322
--- /dev/null
+++ b/src/mir_core/src/openurl.cpp
@@ -0,0 +1,78 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+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; either version 2
+of the License, or (at your option) any later version.
+
+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, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+#include <ctype.h>
+
+struct TOpenUrlInfo
+{
+ TOpenUrlInfo(TCHAR *_url, int _bNew) :
+ szUrl(_url),
+ newWindow(_bNew)
+ {}
+
+ ptrT szUrl;
+ int newWindow;
+};
+
+static void OpenURLThread(void *arg)
+{
+ TOpenUrlInfo *hUrlInfo = (TOpenUrlInfo*)arg;
+
+ // wack a protocol on it
+ CMString tszUrl;
+ if ((isalpha(hUrlInfo->szUrl[0]) && hUrlInfo->szUrl[1] == ':') || hUrlInfo->szUrl[0] == '\\')
+ tszUrl.Format(_T("file:///%s"), hUrlInfo->szUrl);
+ else {
+ int i;
+ for (i = 0; _istalpha(hUrlInfo->szUrl[i]); i++);
+ if (hUrlInfo->szUrl[i] == ':')
+ tszUrl = hUrlInfo->szUrl;
+ else if (!_tcsnicmp(hUrlInfo->szUrl, _T("ftp."), 4))
+ tszUrl.Format(_T("ftp://%s"), hUrlInfo->szUrl);
+ else
+ tszUrl.Format(_T("http://%s"), hUrlInfo->szUrl);
+ }
+
+ // check user defined browser for opening urls
+ ptrT tszBrowser(db_get_tsa(NULL, "Miranda", "OpenUrlBrowser"));
+ if (tszBrowser)
+ ShellExecute(NULL, _T("open"), tszBrowser, tszUrl, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT);
+ else
+ ShellExecute(NULL, _T("open"), tszUrl, NULL, NULL, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT);
+
+ delete hUrlInfo;
+}
+
+MIR_CORE_DLL(void) Utils_OpenUrl(const char *pszUrl, bool bOpenInNewWindow)
+{
+ if (pszUrl)
+ forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_a2t(pszUrl), bOpenInNewWindow));
+}
+
+MIR_CORE_DLL(void) Utils_OpenUrlW(const wchar_t *pszUrl, bool bOpenInNewWindow)
+{
+ if (pszUrl)
+ forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_wstrdup(pszUrl), bOpenInNewWindow));
+}