| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | #include "sharewidget.h"
|
|---|
| 20 | #include "sharedata.h"
|
|---|
| 21 | #include "images.h"
|
|---|
| 22 |
|
|---|
| 23 | #include <QHBoxLayout>
|
|---|
| 24 | #include <QDesktopServices>
|
|---|
| 25 | #include <QSettings>
|
|---|
| 26 | #include <QEvent>
|
|---|
| 27 | #include <QTime>
|
|---|
| 28 |
|
|---|
| 29 | //#define TEST_SHAREWIDGET
|
|---|
| 30 |
|
|---|
| 31 | #define SHAREBUTTON_MIN QSize(24,24)
|
|---|
| 32 | #define SHAREBUTTON_MAX QSize(32,32)
|
|---|
| 33 |
|
|---|
| 34 | ShareButton::ShareButton(const QString icon_name, const QString & tooltip, QWidget * parent)
|
|---|
| 35 | : QPushButton("", parent)
|
|---|
| 36 | {
|
|---|
| 37 | setAttribute(Qt::WA_Hover, true);
|
|---|
| 38 |
|
|---|
| 39 | setIconSize(SHAREBUTTON_MIN);
|
|---|
| 40 | setIcon(Images::icon(icon_name));
|
|---|
| 41 | setToolTip(tooltip);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | QSize ShareButton::sizeHint() const {
|
|---|
| 45 | QSize s(SHAREBUTTON_MAX);
|
|---|
| 46 | s += QSize(4,4);
|
|---|
| 47 | return s;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | void ShareButton::enterEvent(QEvent *) {
|
|---|
| 51 | //qDebug("ShareButton::enterEvent");
|
|---|
| 52 | setIconSize(SHAREBUTTON_MAX);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void ShareButton::leaveEvent(QEvent *) {
|
|---|
| 56 | //qDebug("ShareButton::leaveEvent");
|
|---|
| 57 | setIconSize(SHAREBUTTON_MIN);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | ShareWidget::ShareWidget(QSettings * settings, QWidget * parent, Qt::WindowFlags f)
|
|---|
| 63 | : QWidget(parent,f)
|
|---|
| 64 | , set(settings)
|
|---|
| 65 | , actions_taken(0)
|
|---|
| 66 | , count(0)
|
|---|
| 67 | , display(Random)
|
|---|
| 68 | {
|
|---|
| 69 | QTime now = QTime::currentTime();
|
|---|
| 70 | qsrand(now.msec());
|
|---|
| 71 |
|
|---|
| 72 | donate_button = new ShareButton("paypal", "", this);
|
|---|
| 73 | fb_button = new ShareButton("social_facebook", "", this);
|
|---|
| 74 | twitter_button = new ShareButton("social_twitter", "", this);
|
|---|
| 75 |
|
|---|
| 76 | support_button = new QPushButton(this);
|
|---|
| 77 | support_button->setObjectName("support_button");
|
|---|
| 78 | connect(support_button, SIGNAL(clicked()), this, SIGNAL(supportClicked()));
|
|---|
| 79 |
|
|---|
| 80 | QHBoxLayout * hlayout = new QHBoxLayout;
|
|---|
| 81 | hlayout->setSpacing(0);
|
|---|
| 82 | //hlayout->addSpacerItem(new QSpacerItem(10,10, QSizePolicy::Expanding));
|
|---|
| 83 | hlayout->addWidget(donate_button);
|
|---|
| 84 | hlayout->addWidget(fb_button);
|
|---|
| 85 | hlayout->addWidget(twitter_button);
|
|---|
| 86 | //hlayout->addSpacerItem(new QSpacerItem(10,10, QSizePolicy::Expanding));
|
|---|
| 87 |
|
|---|
| 88 | QVBoxLayout * vlayout = new QVBoxLayout(this);
|
|---|
| 89 | vlayout->setSpacing(0);
|
|---|
| 90 | vlayout->addLayout(hlayout);
|
|---|
| 91 | vlayout->addWidget(support_button);
|
|---|
| 92 |
|
|---|
| 93 | /*
|
|---|
| 94 | setBackgroundRole(QPalette::Window);
|
|---|
| 95 | setAutoFillBackground(true);
|
|---|
| 96 | setStyleSheet("background: yellow;");
|
|---|
| 97 | */
|
|---|
| 98 |
|
|---|
| 99 | connect(donate_button, SIGNAL(clicked()), this, SLOT(donate()));
|
|---|
| 100 | connect(fb_button, SIGNAL(clicked()), this, SLOT(facebook()));
|
|---|
| 101 | connect(twitter_button, SIGNAL(clicked()), this, SLOT(twitter()));
|
|---|
| 102 |
|
|---|
| 103 | retranslateStrings();
|
|---|
| 104 | loadConfig();
|
|---|
| 105 | updateButtons();
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | ShareWidget::~ShareWidget() {
|
|---|
| 109 | saveConfig();
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | void ShareWidget::retranslateStrings() {
|
|---|
| 113 | donate_button->setToolTip(tr("Donate with PayPal"));
|
|---|
| 114 | fb_button->setToolTip(tr("Share SMPlayer in Facebook"));
|
|---|
| 115 | twitter_button->setToolTip(tr("Share SMPlayer in Twitter"));
|
|---|
| 116 |
|
|---|
| 117 | support_button->setText(tr("Support SMPlayer"));
|
|---|
| 118 | support_button->setToolTip(tr("Donate / Share SMPlayer with your friends"));
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | void ShareWidget::updateButtons() {
|
|---|
| 122 | qDebug("ShareWidget::updateButtons: actions_taken: %d", actions_taken);
|
|---|
| 123 |
|
|---|
| 124 | if ((actions_taken & ShareData::Donate) > 0) donate_button->hide();
|
|---|
| 125 | if ((actions_taken & ShareData::Facebook) > 0) fb_button->hide();
|
|---|
| 126 | if ((actions_taken & ShareData::Twitter) > 0) twitter_button->hide();
|
|---|
| 127 |
|
|---|
| 128 | if (actions_taken > 0) support_button->hide();
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | void ShareWidget::loadConfig() {
|
|---|
| 133 | if (set) {
|
|---|
| 134 | set->beginGroup("reminder");
|
|---|
| 135 | actions_taken = set->value("action", 0).toInt();
|
|---|
| 136 | count = set->value("count", 0).toInt();
|
|---|
| 137 | display = set->value("show", Random).toInt();
|
|---|
| 138 | set->endGroup();
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | void ShareWidget::saveConfig() {
|
|---|
| 143 | if (set) {
|
|---|
| 144 | set->beginGroup("reminder");
|
|---|
| 145 | set->setValue("action", actions_taken);
|
|---|
| 146 | set->setValue("count", count);
|
|---|
| 147 | set->setValue("show", display);
|
|---|
| 148 | set->endGroup();
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | void ShareWidget::setActions(int a) {
|
|---|
| 153 | actions_taken = a;
|
|---|
| 154 | updateButtons();
|
|---|
| 155 | saveConfig();
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | void ShareWidget::setActionPerformed(int action) {
|
|---|
| 159 | actions_taken |= action;
|
|---|
| 160 | updateButtons();
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | void ShareWidget::setVisible(bool visible) {
|
|---|
| 164 | //qDebug("ShareWidget::setVisible: %d", visible);
|
|---|
| 165 |
|
|---|
| 166 | #if 1
|
|---|
| 167 | if (!visible) {
|
|---|
| 168 | QWidget::setVisible(false);
|
|---|
| 169 | } else {
|
|---|
| 170 | bool v = true;
|
|---|
| 171 | switch (display) {
|
|---|
| 172 | case Never: v = false; break;
|
|---|
| 173 | case Always: v = visible; break;
|
|---|
| 174 | case Random: {
|
|---|
| 175 | if (actions_taken == 7) {
|
|---|
| 176 | // User already clicked all buttons
|
|---|
| 177 | v = false;
|
|---|
| 178 | } else {
|
|---|
| 179 | if ((qrand() % 10) != 1) v = false;
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 | //qDebug("ShareWidget::setVisible: v: %d", v);
|
|---|
| 184 | QWidget::setVisible(v);
|
|---|
| 185 | }
|
|---|
| 186 | #else
|
|---|
| 187 | QWidget::setVisible(visible);
|
|---|
| 188 | #endif
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | void ShareWidget::donate() {
|
|---|
| 192 | qDebug("ShareWidget::donate");
|
|---|
| 193 | setActionPerformed(ShareData::Donate);
|
|---|
| 194 | #ifndef TEST_SHAREWIDGET
|
|---|
| 195 | QDesktopServices::openUrl( ShareData::donateUrl() );
|
|---|
| 196 | #endif
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | void ShareWidget::facebook() {
|
|---|
| 200 | qDebug("ShareWidget::facebook");
|
|---|
| 201 | setActionPerformed(ShareData::Facebook);
|
|---|
| 202 | #ifndef TEST_SHAREWIDGET
|
|---|
| 203 | QDesktopServices::openUrl( ShareData::facebookUrl() );
|
|---|
| 204 | #endif
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | void ShareWidget::twitter() {
|
|---|
| 208 | qDebug("ShareWidget::twitter");
|
|---|
| 209 | setActionPerformed(ShareData::Twitter);
|
|---|
| 210 | #ifndef TEST_SHAREWIDGET
|
|---|
| 211 | QDesktopServices::openUrl( ShareData::twitterUrl() );
|
|---|
| 212 | #endif
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | // Language change stuff
|
|---|
| 216 | void ShareWidget::changeEvent(QEvent *e) {
|
|---|
| 217 | if (e->type() == QEvent::LanguageChange) {
|
|---|
| 218 | retranslateStrings();
|
|---|
| 219 | } else {
|
|---|
| 220 | QWidget::changeEvent(e);
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | #include "moc_sharewidget.cpp"
|
|---|
| 225 |
|
|---|