diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 5651891..9070643 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,85 +1,87 @@ set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KAccounts") ecm_setup_version(${KACCOUNTS_VERSION} VARIABLE_PREFIX KACCOUNTS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kaccounts_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfigVersion.cmake" SOVERSION ${KACCOUNTS_SOVERSION}) set (kaccountslib_SRCS accountsmodel.cpp core.cpp kaccountsdplugin.cpp kaccountsuiplugin.cpp providersmodel.cpp servicesmodel.cpp uipluginsmanager.cpp accountservicetogglejob.cpp + changeaccountdisplaynamejob.cpp createaccountjob.cpp getcredentialsjob.cpp removeaccountjob.cpp ) ecm_generate_headers(kaccountslib_HEADERS HEADER_NAMES AccountsModel Core KAccountsUiPlugin KAccountsDPlugin ProvidersModel ServicesModel AccountServiceToggleJob - GetCredentialsJob + ChangeAccountDisplayNameJob CreateAccountJob + GetCredentialsJob RemoveAccountJob REQUIRED_HEADERS kaccountslib_HEADERS ) add_library(kaccounts ${kaccountslib_SRCS}) generate_export_header(kaccounts BASE_NAME kaccounts) target_link_libraries (kaccounts PUBLIC KF5::CoreAddons KF5::I18n ${ACCOUNTSQT_LIBRARIES} Qt5::Xml Qt5::Gui PRIVATE ${SIGNONQT_LIBRARIES} ) target_include_directories(kaccounts INTERFACE "$" PUBLIC "${ACCOUNTSQT_INCLUDE_DIRS}" PRIVATE "${SIGNONQT_INCLUDE_DIRS}") set_target_properties(kaccounts PROPERTIES VERSION ${KACCOUNTS_VERSION} SOVERSION ${KACCOUNTS_SOVERSION} EXPORT_NAME KAccounts ) ecm_configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KAccountsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "KAccountsMacros.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KAccountsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(TARGETS kaccounts EXPORT KAccountsTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) install(EXPORT KAccountsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KAccountsTargets.cmake ) #NAMESPACE KF5:: install (FILES ${CMAKE_CURRENT_BINARY_DIR}/kaccounts_export.h ${kaccountslib_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/kaccounts_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KAccounts COMPONENT Devel ) add_subdirectory(cmake) diff --git a/src/lib/changeaccountdisplaynamejob.cpp b/src/lib/changeaccountdisplaynamejob.cpp new file mode 100644 index 0000000..73ed0e0 --- /dev/null +++ b/src/lib/changeaccountdisplaynamejob.cpp @@ -0,0 +1,90 @@ +/************************************************************************************* + * Copyright (C) 2020 by Dan Leinir Turthra Jensen * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * + *************************************************************************************/ + +#include "changeaccountdisplaynamejob.h" + +#include "core.h" +#include +#include +#include + +class ChangeAccountDisplayNameJob::Private { +public: + Private() {} + QString accountId; + QString displayName; +}; + +ChangeAccountDisplayNameJob::ChangeAccountDisplayNameJob(QObject* parent) + : KJob(parent) + , d(new Private) +{ } + +ChangeAccountDisplayNameJob::~ChangeAccountDisplayNameJob() +{ + delete d; +} + +QString ChangeAccountDisplayNameJob::accountId() const +{ + return d->accountId; +} + +void ChangeAccountDisplayNameJob::setAccountId(const QString& accountId) +{ + d->accountId = accountId; + Q_EMIT accountIdChanged(); +} + +QString ChangeAccountDisplayNameJob::displayName() const +{ + return d->displayName; +} + +void ChangeAccountDisplayNameJob::setDisplayName(const QString& displayName) +{ + d->displayName = displayName; + Q_EMIT displayNameChanged(); +} + +void ChangeAccountDisplayNameJob::start() +{ + if (!d->displayName.isEmpty()) { + Accounts::Manager* accountsManager = KAccounts::accountsManager(); + if (accountsManager) { + Accounts::Account *account = accountsManager->account(d->accountId.toInt()); + if (account) { + account->setDisplayName(d->displayName); + connect(account, &Accounts::Account::synced, this, [this](){ emitResult(); }); + account->sync(); + } else { + qWarning() << "No account found with the ID" << d->accountId; + setErrorText(i18n("No account found with the ID %1").arg(d->accountId)); + emitResult(); + } + } else { + qWarning() << "No accounts manager, this is not awesome."; + setErrorText(i18n("No accounts manager, this is not awesome.")); + emitResult(); + } + } else { + qWarning() << "Setting an account display name to empty is a terrible idea, and we refuse to do that"; + setErrorText(i18n("The display name cannot be empty")); + emitResult(); + } +} diff --git a/src/lib/changeaccountdisplaynamejob.h b/src/lib/changeaccountdisplaynamejob.h new file mode 100644 index 0000000..1663ff1 --- /dev/null +++ b/src/lib/changeaccountdisplaynamejob.h @@ -0,0 +1,50 @@ +/************************************************************************************* + * Copyright (C) 2020 by Dan Leinir Turthra Jensen * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * + *************************************************************************************/ + +#ifndef CHANGEACCOUNTDISPLAYNAMEJOB_H +#define CHANGEACCOUNTDISPLAYNAMEJOB_H + +#include "kaccounts_export.h" + +#include + +#include + +class KACCOUNTS_EXPORT ChangeAccountDisplayNameJob : public KJob +{ + Q_OBJECT + Q_PROPERTY(QString accountId READ accountId WRITE setAccountId NOTIFY accountIdChanged) + Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) +public: + explicit ChangeAccountDisplayNameJob(QObject* parent = nullptr); + virtual ~ChangeAccountDisplayNameJob(); + + void start() override; + + QString accountId() const; + void setAccountId(const QString& accountId); + Q_SIGNAL void accountIdChanged(); + + QString displayName() const; + void setDisplayName(const QString& displayName); + Q_SIGNAL void displayNameChanged(); +private: + class Private; + Private* d; +}; +#endif//CHANGEACCOUNTDISPLAYNAMEJOB_H