Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Pass Twitter client secrets as build arguments #107

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Makefile*
# QtCtreator CMake
CMakeLists.txt.user

# Twitter client secrets
src/o2/o1twitterglobals.h
# TWITTER_STORE_DEFAULT_ENCRYPTION_KEY
o2_default_encryption_key
35 changes: 6 additions & 29 deletions rpm/harbour-piepmatz.spec
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
#
# Do NOT Edit the Auto-generated Part!
# Generated by: spectacle version 0.32
#

Name: harbour-piepmatz

# >> macros
# << macros

%{!?qtc_qmake:%define qtc_qmake %qmake}
%{!?qtc_qmake5:%define qtc_qmake5 %qmake5}
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Piepmatz is a Twitter client for Sailfish OS
Version: 1.13
Release: 2
Group: Qt/Qt
License: LICENSE
License: GPLv3
URL: http://werkwolf.de/
Source0: %{name}-%{version}.tar.bz2
Source100: harbour-piepmatz.yaml
Requires: sailfishsilica-qt5 >= 0.10.9
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
BuildRequires: pkgconfig(Qt5Core)
Expand All @@ -38,38 +28,25 @@ Piepmatz is a Twitter client for Sailfish OS
%prep
%setup -q -n %{name}-%{version}

# >> setup
# << setup

%build
# >> build pre
# << build pre

%qtc_qmake5
%qtc_qmake5 \
%{?piepmatz_twitter_client_id: TWITTER_CLIENT_ID=%{piepmatz_twitter_client_id}} \
%{?piepmatz_twitter_client_secret: TWITTER_CLIENT_SECRET=%{piepmatz_twitter_client_secret}}

%qtc_make %{?_smp_mflags}

# >> build post
# << build post
%qtc_make %{?_smp_mflags}

%install
rm -rf %{buildroot}
# >> install pre
# << install pre
%qmake5_install

# >> install post
# << install post

desktop-file-install --delete-original \
--dir %{buildroot}%{_datadir}/applications \
%{buildroot}%{_datadir}/applications/*.desktop

%files
%defattr(-,root,root,-)
%{_bindir}
%{_bindir}/%{name}
%{_datadir}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.png
# >> files
# << files
49 changes: 0 additions & 49 deletions rpm/harbour-piepmatz.yaml

This file was deleted.

16 changes: 7 additions & 9 deletions src/accountmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ void AccountModel::initializeEnvironment()
{
O0SettingsStore *settings = new O0SettingsStore(encryptionKey);
o1->setStore(settings);
o1->setClientId(this->twitterClientId);
o1->setClientSecret(this->twitterClientSecret);
connect(o1, &O1Twitter::pinRequestError, this, &AccountModel::handlePinRequestError);
connect(o1, &O1Twitter::pinRequestSuccessful, this, &AccountModel::handlePinRequestSuccessful);
connect(o1, &O1Twitter::linkingFailed, this, &AccountModel::handleLinkingFailed);
Expand Down Expand Up @@ -423,7 +421,7 @@ void AccountModel::obtainEncryptionKey()
}
QUuid uid(encryptionKey); //make sure this can be made into a valid QUUid
if (uid.isNull()) {
encryptionKey = QString(TWITTER_STORE_DEFAULT_ENCRYPTION_KEY);
encryptionKey = QString(twitter_store_default_encryption_key);
}
qDebug() << "Using encryption key: " + encryptionKey;
}
Expand Down Expand Up @@ -461,8 +459,8 @@ void AccountModel::initializeSecretIdentity()
O0SettingsStore *secretIdentitySettingsStore = new O0SettingsStore(secretIdentitySettings, encryptionKey, this);
O1Twitter *o1SecretIdentity = new O1Twitter(this);
o1SecretIdentity->setStore(secretIdentitySettingsStore);
o1SecretIdentity->setClientId(TWITTER_CLIENT_ID);
o1SecretIdentity->setClientSecret(TWITTER_CLIENT_SECRET);
o1SecretIdentity->setClientId(twitter_client_id);
o1SecretIdentity->setClientSecret(twitter_client_secret);
if (o1SecretIdentity->linked()) {
qDebug() << "Secret identity successfully initialized!";
secretIdentityRequestor = new O1Requestor(manager, o1SecretIdentity, this);
Expand Down Expand Up @@ -593,7 +591,7 @@ void AccountModel::handleEmojiSearchCompleted(const QString &queryString, const

void AccountModel::obtainTwitterSecrets()
{
if (QString(TWITTER_CLIENT_ID).isEmpty()) {
if (QString(twitter_client_id).isEmpty()) {
char *sailfishConsumerKey = NULL;
qDebug() << "Retrieving Twitter consumer key from Sailfish key database...";
int consumerKeyReturnCode = SailfishKeyProvider_storedKey("twitter", "twitter-sync", "consumer_key", &sailfishConsumerKey);
Expand All @@ -602,10 +600,10 @@ void AccountModel::obtainTwitterSecrets()
free(sailfishConsumerKey);
} else {
qDebug() << "This build comes with an own Twitter client ID, good!";
this->twitterClientId = QString(TWITTER_CLIENT_ID);
this->twitterClientId = QString(twitter_client_id);
}

if (QString(TWITTER_CLIENT_SECRET).isEmpty()) {
if (QString(twitter_client_secret).isEmpty()) {
char *sailfishConsumerSecret = NULL;
qDebug() << "Retrieving Twitter consumer secret from Sailfish key database...";
int consumerSecretReturnCode = SailfishKeyProvider_storedKey("twitter", "twitter-sync", "consumer_secret", &sailfishConsumerSecret);
Expand All @@ -614,7 +612,7 @@ void AccountModel::obtainTwitterSecrets()
free(sailfishConsumerSecret);
} else {
qDebug() << "This build comes with an own Twitter client secret, good!";
this->twitterClientSecret = QString(TWITTER_CLIENT_SECRET);
this->twitterClientSecret = QString(twitter_client_secret);
}

}
Expand Down
6 changes: 6 additions & 0 deletions src/o2/o1twitterglobals.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

const char twitter_client_id[] = \"$$TWITTER_CLIENT_ID\";
const char twitter_client_secret[] = \"$$TWITTER_CLIENT_SECRET\";
const char twitter_store_default_encryption_key[] =
\"$$TWITTER_STORE_DEFAULT_ENCRYPTION_KEY\";
6 changes: 0 additions & 6 deletions src/o2/o1twitterglobals.h.sample

This file was deleted.

20 changes: 20 additions & 0 deletions src/o2/src.pri
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ QT *= network
!qtHaveModule(qml): QT *= script
qtHaveModule(qml): QT *= qml

!defined(TWITTER_CLIENT_ID, var) {
warning("TWITTER_CLIENT_ID has to be defined to build o2 with twitter support")
}


!defined(TWITTER_CLIENT_SECRET, var) {
warning("TWITTER_CLIENT_SECRET has to be defined to build o2 with twitter support")
}

!exists($$shadowed($$_PRO_FILE_PWD_)/o2_default_encryption_key) {
system(sh \
-c \
\'cat /proc/sys/kernel/random/uuid| sed -e "s/-//g" > $$shadowed($$_PRO_FILE_PWD_)/o2_default_encryption_key\')
}

TWITTER_STORE_DEFAULT_ENCRYPTION_KEY = \
$$system(cat $$shadowed($$_PRO_FILE_PWD_)/o2_default_encryption_key)

QMAKE_SUBSTITUTES = $$PWD/o1twitterglobals.h.in

INCLUDEPATH += $$PWD
SOURCES += \
$$PWD/o1.cpp \
Expand Down