diff --git a/setup/extensions.py b/setup/extensions.py index 147fbfff5d..5251737101 100644 --- a/setup/extensions.py +++ b/setup/extensions.py @@ -143,7 +143,7 @@ extensions = [ if iswindows: extensions.append(Extension('winutil', ['calibre/utils/windows/winutil.c'], - libraries=['shell32', 'setupapi'], + libraries=['shell32', 'setupapi', 'wininet'], cflags=['/X'] )) diff --git a/src/calibre/utils/windows/winutil.c b/src/calibre/utils/windows/winutil.c index efd8f1400d..2f176043b2 100644 --- a/src/calibre/utils/windows/winutil.c +++ b/src/calibre/utils/windows/winutil.c @@ -51,11 +51,15 @@ wherever possible in this module. script being run. So to replace sys.argv, you should use `if len(sys.argv) > 1: sys.argv[1:] = winutil.argv()[1-len(sys.argv):]` +.. function:: internet_connected() -> Return True if there is an active + internet connection. + */ #define UNICODE #include +#include #include #include #include @@ -771,6 +775,15 @@ gettmarg(PyObject *args, struct tm *p) return 1; } +static PyObject * +winutil_internet_connected(PyObject *self, PyObject *args) { + DWORD flags; + BOOL ans = InternetGetConnectedState(&flags, 0); + if (ans) Py_RETURN_TRUE; + Py_RETURN_FALSE; +} + + static PyObject * winutil_strftime(PyObject *self, PyObject *args) { @@ -919,6 +932,10 @@ be a unicode string. Returns unicode strings." "eject_drive(drive_letter)\n\nEject a drive. Raises an exception on failure." }, + {"internet_connected", winutil_internet_connected, METH_VARARGS, + "internet_connected()\n\nReturn True if there is an active internet connection" + }, + {NULL, NULL, 0, NULL} };