diff --git a/README.md b/README.md new file mode 100644 index 0000000..60e664e --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Gravatar + +Online avatar lookup library. + +Allows to retrieve avatar images based on a hash from a person's email address, as well +as local caching to avoid unnecessary network operations. Use Gravatar::GravatarResolvUrlJob +for this. + +## Backends + +This supports: +* https://gravator.com +* https://www.libravatar.org/ diff --git a/src/job/gravatarresolvurljob.h b/src/job/gravatarresolvurljob.h index 9eaf64a..c3dd231 100644 --- a/src/job/gravatarresolvurljob.h +++ b/src/job/gravatarresolvurljob.h @@ -1,76 +1,77 @@ /* Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRAVATARRESOLVURLJOB_H #define GRAVATARRESOLVURLJOB_H #include "gravatar_export.h" #include #include #include #include class GravatarResolvUrlJobTest; namespace Gravatar { class GravatarResolvUrlJobPrivate; class Hash; +/** Avartar lookup job. */ class GRAVATAR_EXPORT GravatarResolvUrlJob : public QObject { Q_OBJECT public: explicit GravatarResolvUrlJob(QObject *parent = nullptr); ~GravatarResolvUrlJob(); Q_REQUIRED_RESULT bool canStart() const; void start(); Q_REQUIRED_RESULT QString email() const; void setEmail(const QString &email); Q_REQUIRED_RESULT bool hasGravatar() const; void setSize(int size); Q_REQUIRED_RESULT int size() const; Q_REQUIRED_RESULT QPixmap pixmap() const; Q_REQUIRED_RESULT bool useDefaultPixmap() const; void setUseDefaultPixmap(bool useDefaultPixmap); Q_SIGNALS: void finished(Gravatar::GravatarResolvUrlJob *); void resolvUrl(const QUrl &url); private: friend class ::GravatarResolvUrlJobTest; void slotFinishLoadPixmap(QNetworkReply *reply); QUrl generateGravatarUrl(); Hash calculatedHash() const; void processNextBackend(); void startNetworkManager(const QUrl &url); QUrl createUrl(); Hash calculateHash(); bool cacheLookup(const Hash &hash); GravatarResolvUrlJobPrivate *const d; }; } #endif // GRAVATARRESOLVURLJOB_H diff --git a/src/misc/gravatarcache.h b/src/misc/gravatarcache.h index 6e4fe73..2f7407a 100644 --- a/src/misc/gravatarcache.h +++ b/src/misc/gravatarcache.h @@ -1,56 +1,57 @@ /* Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRAVATARCACHE_H #define GRAVATARCACHE_H #include "gravatar_export.h" #include namespace Gravatar { class GravatarCachePrivate; class Hash; +/** Cache for both positive and negative avatar lookups. */ class GRAVATAR_EXPORT GravatarCache { public: static GravatarCache *self(); GravatarCache(); ~GravatarCache(); void saveGravatarPixmap(const Hash &hash, const QPixmap &pixmap); void saveMissingGravatar(const Hash &hash); Q_REQUIRED_RESULT QPixmap loadGravatarPixmap(const Hash &hash, bool &gravatarStored); Q_REQUIRED_RESULT int maximumSize() const; void setMaximumSize(int maximumSize); void clear(); void clearAllCache(); private: Q_DISABLE_COPY(GravatarCache) GravatarCachePrivate *const d; }; } #endif // GRAVATARCACHE_H diff --git a/src/widgets/gravatarconfiguresettingsdialog.h b/src/widgets/gravatarconfiguresettingsdialog.h index 7b46168..335f64d 100644 --- a/src/widgets/gravatarconfiguresettingsdialog.h +++ b/src/widgets/gravatarconfiguresettingsdialog.h @@ -1,42 +1,44 @@ /* Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRAVATARCONFIGURESETTINGSDIALOG_H #define GRAVATARCONFIGURESETTINGSDIALOG_H #include #include "gravatar_export.h" namespace Gravatar { class GravatarConfigureSettingsWidget; + +/** Gravatar settings dialog. */ class GRAVATAR_EXPORT GravatarConfigureSettingsDialog : public QDialog { Q_OBJECT public: explicit GravatarConfigureSettingsDialog(QWidget *parent = nullptr); ~GravatarConfigureSettingsDialog(); private: void slotRestoreDefault(); void save(); void load(); GravatarConfigureSettingsWidget *mGravatarConfigureSettings; }; } #endif // GRAVATARCONFIGURESETTINGSDIALOG_H diff --git a/src/widgets/gravatarconfiguresettingswidget.h b/src/widgets/gravatarconfiguresettingswidget.h index 1dc6076..508291a 100644 --- a/src/widgets/gravatarconfiguresettingswidget.h +++ b/src/widgets/gravatarconfiguresettingswidget.h @@ -1,47 +1,49 @@ /* Copyright (C) 2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRAVATARCONFIGURESETTINGSWIDGET_H #define GRAVATARCONFIGURESETTINGSWIDGET_H #include #include "gravatar_export.h" class QCheckBox; class QPushButton; class KPluralHandlingSpinBox; namespace Gravatar { + +/** Gravatar settings widget. */ class GRAVATAR_EXPORT GravatarConfigureSettingsWidget : public QWidget { Q_OBJECT public: explicit GravatarConfigureSettingsWidget(QWidget *parent = nullptr); ~GravatarConfigureSettingsWidget(); void slotRestoreDefault(); void save(); void load(); private: void slotClearGravatarCache(); QCheckBox *mUseDefaultPixmap = nullptr; QPushButton *mClearGravatarCache = nullptr; KPluralHandlingSpinBox *mGravatarCacheSize = nullptr; }; } #endif // GRAVATARCONFIGURESETTINGSWIDGET_H diff --git a/src/widgets/gravatarconfigwidget.h b/src/widgets/gravatarconfigwidget.h index ca44643..037cc84 100644 --- a/src/widgets/gravatarconfigwidget.h +++ b/src/widgets/gravatarconfigwidget.h @@ -1,49 +1,51 @@ /* Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRAVATARCONFIGWIDGET_H #define GRAVATARCONFIGWIDGET_H #include #include "gravatar_export.h" namespace Gravatar { class GravatarConfigWidgetPrivate; + +/** Gravatar configuration widget. */ class GRAVATAR_EXPORT GravatarConfigWidget : public QWidget { Q_OBJECT public: explicit GravatarConfigWidget(QWidget *parent = nullptr); ~GravatarConfigWidget(); void save(); void doLoadFromGlobalSettings(); void doResetToDefaultsOther(); Q_SIGNALS: void configChanged(bool); private: void slotGravatarEnableChanged(bool state); void slotConfigureSettings(); void updateWidgetState(bool state); GravatarConfigWidgetPrivate *const d; }; } #endif // GRAVATARCONFIGWIDGET_H diff --git a/src/widgets/gravatardownloadpixmapdialog.h b/src/widgets/gravatardownloadpixmapdialog.h index d74da8f..05d9773 100644 --- a/src/widgets/gravatardownloadpixmapdialog.h +++ b/src/widgets/gravatardownloadpixmapdialog.h @@ -1,43 +1,45 @@ /* Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRAVATARDOWNLOADPIXMAPDIALOG_H #define GRAVATARDOWNLOADPIXMAPDIALOG_H #include #include "gravatar_export.h" namespace Gravatar { class GravatarDownloadPixmapWidget; + +/** Avatar download dialog. */ class GRAVATAR_EXPORT GravatarDownloadPixmapDialog : public QDialog { Q_OBJECT public: explicit GravatarDownloadPixmapDialog(QWidget *parent = nullptr); ~GravatarDownloadPixmapDialog(); Q_REQUIRED_RESULT QPixmap gravatarPixmap() const; private: void slotAccepted(); Gravatar::GravatarDownloadPixmapWidget *mGravatarDownloadPixmapWidget = nullptr; }; } #endif // GRAVATARDOWNLOADPIXMAPDIALOG_H diff --git a/src/widgets/gravatardownloadpixmapwidget.h b/src/widgets/gravatardownloadpixmapwidget.h index 6938a2e..70d6146 100644 --- a/src/widgets/gravatardownloadpixmapwidget.h +++ b/src/widgets/gravatardownloadpixmapwidget.h @@ -1,51 +1,53 @@ /* Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef GRAVATARDOWNLOADPIXMAPWIDGET_H #define GRAVATARDOWNLOADPIXMAPWIDGET_H #include #include "gravatar_export.h" class QLabel; class QLineEdit; class QPushButton; namespace Gravatar { class GravatarResolvUrlJob; + +/** Avatar download widget. */ class GRAVATAR_EXPORT GravatarDownloadPixmapWidget : public QWidget { Q_OBJECT public: explicit GravatarDownloadPixmapWidget(QWidget *parent = nullptr); ~GravatarDownloadPixmapWidget(); Q_REQUIRED_RESULT QPixmap gravatarPixmap() const; private: void slotSearchButton(); void slotTextChanged(const QString &text); void slotResolvUrlFinish(Gravatar::GravatarResolvUrlJob *job); QPixmap mGravatarPixmap; QLabel *mResultLabel = nullptr; QLineEdit *mLineEdit = nullptr; QPushButton *mGetPixmapButton = nullptr; }; } #endif // GRAVATARDOWNLOADPIXMAPWIDGET_H