Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Ask for donations, Transmission-style.
Browse files Browse the repository at this point in the history
At most once a week a popup asking for donations is shown. The user can
dismiss it forever by checking the "Don't bug me about this again"
checkbox to minimize obtrusiveness.
  • Loading branch information
vslavik committed Sep 9, 2012
1 parent 7926628 commit 5a8dae3
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
1 change: 1 addition & 0 deletions icons/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pixmaps_DATA = appicon/48x48/apps/poedit.png


uiicons_DATA = \
appicon/128x128/apps/poedit.png
ui/toolbar-24/document-open.png \
ui/toolbar-24/document-save.png \
ui/toolbar-24/document-properties.png \
Expand Down
1 change: 1 addition & 0 deletions macosx/make-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ find $bundle/Contents/Resources/locale -type f
# icons:
iconsdir="$bundle/Contents/Resources/icons"
mkdir -p $iconsdir
cp $top_srcdir/icons/appicon/128x128/apps/poedit.png $iconsdir
cp $top_srcdir/icons/ui/*.png $iconsdir
cp $top_srcdir/icons/ui/toolbar-32/*.png $iconsdir
# now overwrite with Mac-specific ones:
Expand Down
94 changes: 91 additions & 3 deletions src/edapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <wx/filename.h>
#include <wx/sysopt.h>
#include <wx/aboutdlg.h>
#include <wx/artprov.h>
#include <wx/datetime.h>
#include <wx/intl.h>
#if wxCHECK_VERSION(2,9,1)
#include <wx/translation.h>
Expand Down Expand Up @@ -265,15 +267,24 @@ void PoeditApp::SetupLanguage()

void PoeditApp::OpenNewFile()
{
wxWindow *win;
if (wxConfig::Get()->Read(_T("manager_startup"), (long)false))
ManagerFrame::Create()->Show(true);
{
win = ManagerFrame::Create();
win->Show(true);
}
else
PoeditFrame::Create();
{
win = PoeditFrame::Create();
}

AskForDonations(win);
}

void PoeditApp::OpenFile(const wxString& name)
{
PoeditFrame::Create(name);
wxWindow *win = PoeditFrame::Create(name);
AskForDonations(win);
}

void PoeditApp::SetDefaultParsers(wxConfigBase *cfg)
Expand Down Expand Up @@ -571,3 +582,80 @@ void PoeditApp::OnHelp(wxCommandEvent&)
{
wxLaunchDefaultBrowser(_T("http://www.poedit.net/trac/wiki/Doc"));
}


void PoeditApp::AskForDonations(wxWindow *parent)
{
wxConfigBase *cfg = wxConfigBase::Get();

if ( (bool)cfg->Read(_T("donate/dont_bug"), (long)false) )
return; // the user doesn't like us, don't be a bother
if ( (bool)cfg->Read(_T("donate/donated"), (long)false) )
return; // the user likes us a lot, don't be a bother

wxDateTime lastAsked((time_t)cfg->Read(_T("donate/last_asked"), (long)0));

wxDateTime now = wxDateTime::Now();
if ( lastAsked.Add(wxDateSpan::Days(7)) >= now )
return; // don't ask too frequently

// let's ask nicely:
wxDialog dlg(parent, wxID_ANY, _T(""));
wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);

wxIcon icon(wxArtProvider::GetIcon(_T("poedit"), wxART_OTHER, wxSize(64,64)));
topsizer->Add(new wxStaticBitmap(&dlg, wxID_ANY, icon), wxSizerFlags().DoubleBorder());

wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
topsizer->Add(sizer, wxSizerFlags(1).Expand().DoubleBorder());

wxStaticText *big = new wxStaticText(&dlg, wxID_ANY, _T("Support Open Source software"));
wxFont font = big->GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD);
#if defined(__WXMSW__) && wxCHECK_VERSION(2,9,1)
font.MakeLarger();
#endif
big->SetFont(font);
sizer->Add(big);

wxStaticText *desc = new wxStaticText(&dlg, wxID_ANY,
_T("A lot of time and effort have gone into development\n")
_T("of Poedit. If it's useful to you, please consider showing\n")
_T("your appreciation with a donation.\n")
_T("\n")
_T("Donate or not, there will be no difference in Poedit's\n")
_T("features and functionality.")
);
#ifdef __WXMAC__
desc->SetWindowVariant(wxWINDOW_VARIANT_SMALL);
#endif
sizer->Add(desc, wxSizerFlags(1).Expand().DoubleBorder(wxTOP|wxBOTTOM|wxRIGHT));

wxCheckBox *checkbox = new wxCheckBox(&dlg, wxID_ANY, _T("Don't bug me about this again"));
sizer->Add(checkbox);

wxStdDialogButtonSizer *buttons = new wxStdDialogButtonSizer();
wxButton *ok = new wxButton(&dlg, wxID_OK, _("Donate..."));
ok->SetDefault();
buttons->AddButton(ok);
buttons->AddButton(new wxButton(&dlg, wxID_CANCEL, _("No, thanks")));
buttons->Realize();
sizer->Add(buttons, wxSizerFlags().Right().DoubleBorder(wxTOP));
dlg.SetSizerAndFit(topsizer);
dlg.Centre();

if ( dlg.ShowModal() == wxID_OK )
{
wxLaunchDefaultBrowser(_T("http://www.poedit.net/donate.php"));
cfg->Write(_T("donate/donated"), true);
}
else
{
cfg->Write(_T("donate/dont_bug"), checkbox->GetValue());
}

cfg->Write(_T("donate/last_asked"), (long)now.GetTicks());

// re-asking after a crash wouldn't be a good idea:
cfg->Flush();
}
1 change: 1 addition & 0 deletions src/edapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class PoeditApp : public wxApp

private:
void SetupLanguage();
void AskForDonations(wxWindow *parent);

// App-global menu commands:
void OnNew(wxCommandEvent& event);
Expand Down
1 change: 1 addition & 0 deletions win32/poedit.iss
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Source: deps\db\build_windows\Win32\Release\libdb*.dll; DestDir: {app}\bin; Flag
Source: deps\winsparkle\Release\WinSparkle.dll; DestDir: {app}\bin; Flags: ignoreversion
Source: COPYING; DestDir: {app}\doc; DestName: copying.txt
Source: NEWS; DestDir: {app}\doc; DestName: news.txt
Source: icons\appicon\128x128\apps\poedit.png; DestDir: {app}\share\poedit\icons
Source: icons\ui\*.png; DestDir: {app}\share\poedit\icons
Source: icons\ui\toolbar-32\*.png; DestDir: {app}\share\poedit\icons
Source: icons\win32\xp\*.ico; DestDir: {app}\share\poedit\icons; OnlyBelowVersion: 0,6.0.6000
Expand Down

0 comments on commit 5a8dae3

Please sign in to comment.