gnc-features.cpp (gnucash-5.0.tar.bz2) | : | gnc-features.cpp (gnucash-5.1.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
* * | * * | |||
* You should have received a copy of the GNU General Public License* | * You should have received a copy of the GNU General Public License* | |||
* along with this program; if not, write to the Free Software * | * along with this program; if not, write to the Free Software * | |||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * | |||
* * | * * | |||
\********************************************************************/ | \********************************************************************/ | |||
#include <unordered_map> | #include <unordered_map> | |||
#include <string> | #include <string> | |||
#include <numeric> | #include <numeric> | |||
#include <algorithm> | ||||
#include <config.h> | #include <config.h> | |||
#include <glib.h> | #include <glib.h> | |||
#include <glib/gi18n.h> | #include <glib/gi18n.h> | |||
#include "qofbook.h" | ||||
#include "qofbook.hpp" | #include "qofbook.hpp" | |||
#include "gnc-features.h" | #include "gnc-features.h" | |||
static const FeaturesTable features_table | static const FeaturesTable features_table | |||
{ | { | |||
{ GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at l east GnuCash 2.5.0)" }, | { GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at l east GnuCash 2.5.0)" }, | |||
{ GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; eith er transaction number or split action (requires at least GnuCash 2.5.0)" }, | { GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; eith er transaction number or split action (requires at least GnuCash 2.5.0)" }, | |||
{ GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice ent ries (requires at least GnuCash 2.6.4)" }, | { GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice ent ries (requires at least GnuCash 2.6.4)" }, | |||
{ GNC_FEATURE_GUID_BAYESIAN, "Use account GUID as key for Bayesian data (req uires at least GnuCash 2.6.12)" }, | { GNC_FEATURE_GUID_BAYESIAN, "Use account GUID as key for Bayesian data (req uires at least GnuCash 2.6.12)" }, | |||
{ GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)" }, | { GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)" }, | |||
{ GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQL ite3 databases (requires at least GnuCash 2.6.20)"}, | { GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQL ite3 databases (requires at least GnuCash 2.6.20)"}, | |||
{ GNC_FEATURE_REG_SORT_FILTER, "Store the register sort and filter settings in .gcm metadata file (requires at least GnuCash 3.3)"}, | { GNC_FEATURE_REG_SORT_FILTER, "Store the register sort and filter settings in .gcm metadata file (requires at least GnuCash 3.3)"}, | |||
{ GNC_FEATURE_BUDGET_UNREVERSED, "Store budget amounts unreversed (i.e. natu ral) signs (requires at least Gnucash 3.8)"}, | { GNC_FEATURE_BUDGET_UNREVERSED, "Store budget amounts unreversed (i.e. natu ral) signs (requires at least Gnucash 3.8)"}, | |||
{ GNC_FEATURE_BUDGET_SHOW_EXTRA_ACCOUNT_COLS, "Show extra account columns in the Budget View (requires at least Gnucash 3.8)"}, | { GNC_FEATURE_BUDGET_SHOW_EXTRA_ACCOUNT_COLS, "Show extra account columns in the Budget View (requires at least Gnucash 3.8)"}, | |||
{ GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE, GNC_FEATURE_EQUITY_TYPE_OPENING_B ALANCE " (requires at least Gnucash 4.3)" }, | { GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE, GNC_FEATURE_EQUITY_TYPE_OPENING_B ALANCE " (requires at least Gnucash 4.3)" }, | |||
}; | }; | |||
/* To obsolete a feature leave the #define in gnc-features.h and move the | ||||
* feature from features_table to obsolete_features after removing all of the | ||||
* code that depends on the feature. The feature will be removed from the book's | ||||
* KVP, allowing the book to be opened with GnuCash versions that don't support | ||||
* the feature. | ||||
* | ||||
* Do this only if the book's data is restored to compatibility with older | ||||
* GnuCash versions lacking the feature. In general this can be used only in | ||||
* cases where a feature was created but never implemented in a way that affects | ||||
* the book's data. | ||||
*/ | ||||
static const FeaturesTable obsolete_features{ | ||||
{GNC_FEATURE_BOOK_CURRENCY, "User-specified book currency stored in KVP. Nev | ||||
er implemented but some user managed to get it set anyway. (requires at least Gn | ||||
uCash 2.7.0)"}, | ||||
}; | ||||
/* This static indicates the debugging module that this .o belongs to. */ | /* This static indicates the debugging module that this .o belongs to. */ | |||
static QofLogModule log_module = G_LOG_DOMAIN; | static QofLogModule log_module = G_LOG_DOMAIN; | |||
/********************************************************************\ | /********************************************************************\ | |||
\********************************************************************/ | \********************************************************************/ | |||
static const char* | static const char* | |||
header = N_("This Dataset contains features not supported " | header = N_("This Dataset contains features not supported " | |||
"by this version of GnuCash. You must use a " | "by this version of GnuCash. You must use a " | |||
"newer version of GnuCash in order to support " | "newer version of GnuCash in order to support " | |||
"the following features:"); | "the following features:"); | |||
/* Check if the session requires features unknown to this version of GnuCash. | /* Check if the session requires features unknown to this version of GnuCash. | |||
* | * | |||
* Returns a message to display if we found unknown features, NULL if | * Returns a message to display if we found unknown features, NULL if | |||
* we're okay. | * we're okay. | |||
*/ | */ | |||
gchar *gnc_features_test_unknown (QofBook *book) | gchar *gnc_features_test_unknown (QofBook *book) | |||
{ | { | |||
auto unknowns {qof_book_get_unknown_features (book, features_table)}; | auto unknowns {qof_book_get_unknown_features (book, features_table)}; | |||
auto accum = [](const auto& a, const auto& b){ return a + "\n* " + b; }; | if (unknowns.empty()) | |||
return unknowns.empty() ? nullptr : | return nullptr; | |||
g_strdup (std::accumulate (unknowns.begin(), unknowns.end(), | ||||
std::string (_(header)), accum).c_str()); | auto obsolete = std::remove_if(unknowns.begin(), unknowns.end(), | |||
[](auto& unknown){ | ||||
return obsolete_features.find(unknown.fir | ||||
st) != obsolete_features.end(); | ||||
}); | ||||
while (obsolete != unknowns.end()) | ||||
{ | ||||
qof_book_unset_feature(book, obsolete->first.data()); | ||||
obsolete = unknowns.erase(obsolete); | ||||
} | ||||
if (unknowns.empty()) | ||||
return nullptr; | ||||
auto accum = [](const auto& a, const auto& b){ return a + "\n* " + b.second. | ||||
data(); }; | ||||
auto msg {std::accumulate (unknowns.begin(), unknowns.end(), | ||||
std::string (_(header)), accum)}; | ||||
return g_strdup (msg.c_str()); | ||||
} | } | |||
void gnc_features_set_used (QofBook *book, const gchar *feature) | void gnc_features_set_used (QofBook *book, const gchar *feature) | |||
{ | { | |||
g_return_if_fail (book); | g_return_if_fail (book); | |||
g_return_if_fail (feature); | g_return_if_fail (feature); | |||
/* Can't set an unknown feature */ | /* Can't set an unknown feature */ | |||
auto iter = features_table.find (feature); | auto iter = features_table.find (feature); | |||
if (iter == features_table.end ()) | if (iter == features_table.end ()) | |||
{ | { | |||
PWARN("Tried to set unknown feature as used."); | PWARN("Tried to set unknown feature as used."); | |||
return; | return; | |||
} | } | |||
qof_book_set_feature (book, feature, iter->second.c_str()); | qof_book_set_feature (book, feature, iter->second.data()); | |||
} | } | |||
void gnc_features_set_unused (QofBook *book, const gchar *feature) | void gnc_features_set_unused (QofBook *book, const gchar *feature) | |||
{ | { | |||
g_return_if_fail (book); | g_return_if_fail (book); | |||
g_return_if_fail (feature); | g_return_if_fail (feature); | |||
/* Can't set an unknown feature */ | /* Can't set an unknown feature */ | |||
auto iter = features_table.find (feature); | auto iter = features_table.find (feature); | |||
if (iter == features_table.end ()) | if (iter == features_table.end ()) | |||
End of changes. 5 change blocks. | ||||
5 lines changed or deleted | 42 lines changed or added |