Commit d08067e2 authored by Slava Monich's avatar Slava Monich

Merge pull request #38 from monich/mms_settings

Support for persistent per-SIM settings
parents c8b209d7 5ac2cb8a
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "mms_ofono_log.h" #include "mms_ofono_log.h"
#include "mms_lib_log.h" #include "mms_lib_log.h"
#include "mms_lib_util.h" #include "mms_lib_util.h"
#include "mms_dispatcher.h" #include "mms_settings.h"
#define RET_OK (0) #define RET_OK (0)
#define RET_ERR (1) #define RET_ERR (1)
...@@ -27,10 +27,11 @@ ...@@ -27,10 +27,11 @@
/* Options configurable from the command line */ /* Options configurable from the command line */
typedef struct mms_app_options { typedef struct mms_app_options {
GBusType bus_type; GBusType bus_type;
gboolean keep_running; int flags;
char* dir; char* dir;
char* user_agent; char* user_agent;
MMSConfig config; MMSConfig config;
MMSSettingsSimData settings;
} MMSAppOptions; } MMSAppOptions;
/* All known log modules */ /* All known log modules */
...@@ -161,26 +162,18 @@ mms_app_parse_options( ...@@ -161,26 +162,18 @@ mms_app_parse_options(
#ifdef MMS_ENGINE_VERSION #ifdef MMS_ENGINE_VERSION
gboolean print_version = FALSE; gboolean print_version = FALSE;
#endif #endif
gint size_limit_kb = opt->config.size_limit/1024; gboolean keep_running = FALSE;
gdouble megapixels = opt->config.max_pixels / 1000000.0; gint size_limit_kb = -1;
gdouble megapixels = -1;
char* root_dir_help = g_strdup_printf( char* root_dir_help = g_strdup_printf(
"Root directory for MMS files [%s]", "Root directory for MMS files [%s]",
opt->config.root_dir); opt->config.root_dir);
char* user_agent_help = g_strdup_printf(
"User-Agent [%s]",
opt->config.user_agent);
char* retry_secs_help = g_strdup_printf( char* retry_secs_help = g_strdup_printf(
"Retry period in seconds [%d]", "Retry period in seconds [%d]",
opt->config.retry_secs); opt->config.retry_secs);
char* idle_secs_help = g_strdup_printf( char* idle_secs_help = g_strdup_printf(
"Inactivity timeout in seconds [%d]", "Inactivity timeout in seconds [%d]",
opt->config.idle_secs); opt->config.idle_secs);
char* size_limit_help = g_strdup_printf(
"Maximum size for outgoing messages [%d]",
size_limit_kb);
char* megapixels_help = g_strdup_printf(
"Maximum pixel count for outgoing images [%.1f]",
megapixels);
char* description = mms_log_description(mms_app_log_modules, char* description = mms_log_description(mms_app_log_modules,
G_N_ELEMENTS(mms_app_log_modules)); G_N_ELEMENTS(mms_app_log_modules));
...@@ -195,12 +188,12 @@ mms_app_parse_options( ...@@ -195,12 +188,12 @@ mms_app_parse_options(
{ "idle-secs", 'i', 0, G_OPTION_ARG_INT, { "idle-secs", 'i', 0, G_OPTION_ARG_INT,
&opt->config.idle_secs, idle_secs_help, "SEC" }, &opt->config.idle_secs, idle_secs_help, "SEC" },
{ "size-limit", 's', 0, G_OPTION_ARG_INT, { "size-limit", 's', 0, G_OPTION_ARG_INT,
&size_limit_kb, size_limit_help, "KB" }, &size_limit_kb, "Maximum size for outgoing messages", "KB" },
{ "pix-limit", 'p', 0, G_OPTION_ARG_DOUBLE, { "pix-limit", 'p', 0, G_OPTION_ARG_DOUBLE,
&megapixels, megapixels_help, "MPIX" }, &megapixels, "Maximum pixel count for outgoing images", "MPIX" },
{ "user-agent", 'u', 0, G_OPTION_ARG_STRING, { "user-agent", 'u', 0, G_OPTION_ARG_STRING,
&opt->user_agent, user_agent_help, "STRING" }, &opt->user_agent, "User-Agent header", "STRING" },
{ "keep-running", 'k', 0, G_OPTION_ARG_NONE, &opt->keep_running, { "keep-running", 'k', 0, G_OPTION_ARG_NONE, &keep_running,
"Keep running after everything is done", NULL }, "Keep running after everything is done", NULL },
{ "keep-temp-files", 't', 0, G_OPTION_ARG_NONE, { "keep-temp-files", 't', 0, G_OPTION_ARG_NONE,
&opt->config.keep_temp_files, &opt->config.keep_temp_files,
...@@ -228,37 +221,41 @@ mms_app_parse_options( ...@@ -228,37 +221,41 @@ mms_app_parse_options(
ok = g_option_context_parse(options, &argc, &argv, &error); ok = g_option_context_parse(options, &argc, &argv, &error);
g_option_context_free(options); g_option_context_free(options);
g_free(root_dir_help); g_free(root_dir_help);
g_free(user_agent_help);
g_free(retry_secs_help); g_free(retry_secs_help);
g_free(idle_secs_help); g_free(idle_secs_help);
g_free(size_limit_help);
g_free(megapixels_help);
g_free(description); g_free(description);
#ifdef MMS_ENGINE_VERSION #ifdef MMS_ENGINE_VERSION
# define MMS_STRING__(x) #x # define MMS_STRING__(x) #x
# define MMS_STRING_(x) MMS_STRING__(x) # define MMS_STRING_(x) MMS_STRING__(x)
# define MMS_VERVION_STRING MMS_STRING_(MMS_ENGINE_VERSION)
if (print_version) { if (print_version) {
printf("MMS engine %s\n", MMS_STRING_(MMS_ENGINE_VERSION)); printf("MMS engine %s\n", MMS_VERVION_STRING);
*result = RET_OK; *result = RET_OK;
return FALSE; return FALSE;
} else } else
#endif #endif
if (ok) { if (ok) {
#ifdef MMS_ENGINE_VERSION
MMS_INFO("Version %s starting", MMS_VERVION_STRING);
#else
MMS_INFO("Starting"); MMS_INFO("Starting");
#endif
if (size_limit_kb >= 0) { if (size_limit_kb >= 0) {
opt->config.size_limit = size_limit_kb * 1024; opt->settings.size_limit = size_limit_kb * 1024;
} else { opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT;
opt->config.size_limit = 0;
} }
if (megapixels >= 0) { if (megapixels >= 0) {
opt->config.max_pixels = (int)(megapixels*1000)*1000; opt->settings.max_pixels = (int)(megapixels*1000)*1000;
} else { opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS;
opt->config.max_pixels = 0; }
if (opt->user_agent) {
opt->settings.user_agent = opt->user_agent;
opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT;
} }
if (opt->dir) opt->config.root_dir = opt->dir; if (opt->dir) opt->config.root_dir = opt->dir;
if (opt->user_agent) opt->config.user_agent = opt->user_agent; if (keep_running) opt->flags |= MMS_ENGINE_FLAG_KEEP_RUNNING;
if (session_bus) { if (session_bus) {
MMS_DEBUG("Attaching to session bus"); MMS_DEBUG("Attaching to session bus");
opt->bus_type = G_BUS_TYPE_SESSION; opt->bus_type = G_BUS_TYPE_SESSION;
...@@ -283,13 +280,12 @@ int main(int argc, char* argv[]) ...@@ -283,13 +280,12 @@ int main(int argc, char* argv[])
mms_lib_init(argv[0]); mms_lib_init(argv[0]);
mms_log_default.name = MMS_APP_LOG_PREFIX; mms_log_default.name = MMS_APP_LOG_PREFIX;
mms_lib_default_config(&opt.config); mms_lib_default_config(&opt.config);
mms_settings_sim_data_default(&opt.settings);
if (mms_app_parse_options(&opt, argc, argv, &result)) { if (mms_app_parse_options(&opt, argc, argv, &result)) {
MMSEngine* engine; MMSEngine* engine;
unsigned int engine_flags = 0;
if (opt.keep_running) engine_flags |= MMS_ENGINE_FLAG_KEEP_RUNNING;
/* Create engine instance. This may fail */ /* Create engine instance. This may fail */
engine = mms_engine_new(&opt.config, engine_flags, engine = mms_engine_new(&opt.config, &opt.settings, opt.flags,
mms_app_log_modules, G_N_ELEMENTS(mms_app_log_modules)); mms_app_log_modules, G_N_ELEMENTS(mms_app_log_modules));
if (engine) { if (engine) {
guint name_id; guint name_id;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "mms_engine.h" #include "mms_engine.h"
#include "mms_dispatcher.h" #include "mms_dispatcher.h"
#include "mms_settings.h"
#include "mms_lib_util.h" #include "mms_lib_util.h"
#include "mms_ofono_connman.h" #include "mms_ofono_connman.h"
#include "mms_handler_dbus.h" #include "mms_handler_dbus.h"
...@@ -54,9 +55,9 @@ struct mms_engine { ...@@ -54,9 +55,9 @@ struct mms_engine {
typedef GObjectClass MMSEngineClass; typedef GObjectClass MMSEngineClass;
G_DEFINE_TYPE(MMSEngine, mms_engine, G_TYPE_OBJECT); G_DEFINE_TYPE(MMSEngine, mms_engine, G_TYPE_OBJECT);
#define MMS_ENGINE_TYPE (mms_engine_get_type()) #define MMS_TYPE_ENGINE (mms_engine_get_type())
#define MMS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\ #define MMS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
MMS_ENGINE_TYPE, MMSEngine)) MMS_TYPE_ENGINE, MMSEngine))
inline static MMSEngine* inline static MMSEngine*
mms_engine_from_dispatcher_delegate(MMSDispatcherDelegate* delegate) mms_engine_from_dispatcher_delegate(MMSDispatcherDelegate* delegate)
...@@ -408,15 +409,31 @@ mms_engine_handle_set_log_type( ...@@ -408,15 +409,31 @@ mms_engine_handle_set_log_type(
MMSEngine* MMSEngine*
mms_engine_new( mms_engine_new(
const MMSConfig* config, const MMSConfig* config,
const MMSSettingsSimData* override,
unsigned int flags, unsigned int flags,
MMSLogModule* log_modules[], MMSLogModule* log_modules[],
int log_count) int log_count)
{ {
MMSConnMan* cm = mms_connman_ofono_new(); MMSConnMan* cm = mms_connman_ofono_new();
if (cm) { if (cm) {
MMSEngine* mms = g_object_new(MMS_ENGINE_TYPE, NULL); MMSEngine* mms = g_object_new(MMS_TYPE_ENGINE, NULL);
MMSHandler* handler = mms_handler_dbus_new(); MMSHandler* handler = mms_handler_dbus_new();
mms->dispatcher = mms_dispatcher_new(config, cm, handler); MMSSettings* settings = mms_settings_default_new(config);
if (flags & MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT) {
g_free(settings->sim_defaults.user_agent);
settings->sim_defaults.data.user_agent =
settings->sim_defaults.user_agent = g_strdup(override->user_agent);
}
if (flags & MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT) {
settings->sim_defaults.data.size_limit = override->size_limit;
}
if (flags & MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS) {
settings->sim_defaults.data.max_pixels = override->max_pixels;
}
mms->dispatcher = mms_dispatcher_new(settings, cm, handler);
mms_settings_unref(settings);
mms_connman_unref(cm); mms_connman_unref(cm);
mms_handler_unref(handler); mms_handler_unref(handler);
mms_dispatcher_set_delegate(mms->dispatcher, mms_dispatcher_set_delegate(mms->dispatcher,
......
...@@ -15,22 +15,25 @@ ...@@ -15,22 +15,25 @@
#ifndef JOLLA_MMS_ENGINE_H #ifndef JOLLA_MMS_ENGINE_H
#define JOLLA_MMS_ENGINE_H #define JOLLA_MMS_ENGINE_H
#include <glib.h>
#include <gio/gio.h> #include <gio/gio.h>
#include "mms_lib_types.h" #include "mms_settings.h"
#define MMS_APP_LOG_PREFIX "mms-engine" #define MMS_APP_LOG_PREFIX "mms-engine"
#define MMS_ENGINE_SERVICE "org.nemomobile.MmsEngine" #define MMS_ENGINE_SERVICE "org.nemomobile.MmsEngine"
#define MMS_ENGINE_PATH "/" #define MMS_ENGINE_PATH "/"
#define MMS_ENGINE_FLAG_KEEP_RUNNING (0x01) #define MMS_ENGINE_FLAG_KEEP_RUNNING (0x01)
#define MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT (0x02)
#define MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT (0x04)
#define MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS (0x08)
typedef struct mms_engine MMSEngine; typedef struct mms_engine MMSEngine;
MMSEngine* MMSEngine*
mms_engine_new( mms_engine_new(
const MMSConfig* config, const MMSConfig* config,
const MMSSettingsSimData* settings,
unsigned int flags, unsigned int flags,
MMSLogModule* log_modules[], MMSLogModule* log_modules[],
int log_count); int log_count);
......
...@@ -24,12 +24,31 @@ all: debug release ...@@ -24,12 +24,31 @@ all: debug release
# Sources # Sources
# #
SRC = mms_attachment.c mms_attachment_image.c mms_attachment_jpeg.c \ SRC = \
mms_codec.c mms_connection.c mms_connman.c mms_dispatcher.c mms_error.c \ mms_attachment.c \
mms_handler.c mms_lib_util.c mms_file_util.c mms_log.c mms_message.c \ mms_attachment_image.c \
mms_task.c mms_task_ack.c mms_task_decode.c mms_task_encode.c \ mms_attachment_jpeg.c \
mms_task_http.c mms_task_notification.c mms_task_notifyresp.c \ mms_codec.c \
mms_task_publish.c mms_task_read.c mms_task_retrieve.c mms_task_send.c \ mms_connection.c \
mms_connman.c \
mms_dispatcher.c \
mms_error.c \
mms_handler.c \
mms_lib_util.c \
mms_file_util.c \
mms_log.c mms_message.c \
mms_settings.c \
mms_task.c \
mms_task_ack.c \
mms_task_decode.c \
mms_task_encode.c \
mms_task_http.c \
mms_task_notification.c \
mms_task_notifyresp.c \
mms_task_publish.c \
mms_task_read.c \
mms_task_retrieve.c \
mms_task_send.c \
mms_util.c mms_util.c
ifeq ($(MMS_RESIZE),Qt) ifeq ($(MMS_RESIZE),Qt)
......
...@@ -28,7 +28,7 @@ struct mms_dispatcher_delegate { ...@@ -28,7 +28,7 @@ struct mms_dispatcher_delegate {
MMSDispatcher* MMSDispatcher*
mms_dispatcher_new( mms_dispatcher_new(
const MMSConfig* config, MMSSettings* settings,
MMSConnMan* cm, MMSConnMan* cm,
MMSHandler* handler); MMSHandler* handler);
......
...@@ -43,19 +43,6 @@ ...@@ -43,19 +43,6 @@
# define HAVE_REALPATH # define HAVE_REALPATH
#endif #endif
/* Static configuration, chosen at startup and never changing since then */
typedef struct mms_config {
const char* root_dir; /* Root directory for storing MMS files */
const char* user_agent; /* User agent string */
int retry_secs; /* Retry timeout in seconds */
int idle_secs; /* Idle timeout */
gsize size_limit; /* Maximum size of m-Send.req PDU */
guint max_pixels; /* Pixel limit for outbound images */
gboolean keep_temp_files; /* Keep temporary files around */
gboolean attic_enabled; /* Keep unrecognized push message in attic */
gboolean send_dr; /* Allow sending delivery reports */
} MMSConfig;
/* Attachment information */ /* Attachment information */
typedef struct mms_attachment_info { typedef struct mms_attachment_info {
const char* file_name; /* Full path name */ const char* file_name; /* Full path name */
...@@ -64,6 +51,9 @@ typedef struct mms_attachment_info { ...@@ -64,6 +51,9 @@ typedef struct mms_attachment_info {
} MMSAttachmentInfo; } MMSAttachmentInfo;
/* Types */ /* Types */
typedef struct mms_config MMSConfig;
typedef struct mms_settings MMSSettings;
typedef struct mms_settings_sim_data MMSSettingsSimData;
typedef struct mms_handler MMSHandler; typedef struct mms_handler MMSHandler;
typedef struct mms_connman MMSConnMan; typedef struct mms_connman MMSConnMan;
typedef struct mms_log_module MMSLogModule; typedef struct mms_log_module MMSLogModule;
......
/*
* Copyright (C) 2014 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.
*
*/
#ifndef JOLLA_MMS_SETTINGS_H
#define JOLLA_MMS_SETTINGS_H
#include "mms_lib_types.h"
/* Static configuration, chosen at startup and never changing since then */
struct mms_config {
const char* root_dir; /* Root directory for storing MMS files */
int retry_secs; /* Retry timeout in seconds */
int idle_secs; /* Idle timeout */
gboolean keep_temp_files; /* Keep temporary files around */
gboolean attic_enabled; /* Keep unrecognized push message in attic */
};
/* Persistent mutable per-SIM settings */
struct mms_settings_sim_data {
const char* user_agent; /* User agent string */
unsigned int size_limit; /* Maximum size of m-Send.req PDU */
unsigned int max_pixels; /* Pixel limit for outbound images */
gboolean allow_dr; /* Allow sending delivery reports */
};
/* Copy of per-SIM settings */
typedef struct mms_settings_sim_data_copy {
MMSSettingsSimData data; /* Settings data */
char* user_agent; /* Allocated copy of user_agent */
} MMSSettingsSimDataCopy;
/* Instance */
struct mms_settings {
GObject object;
const MMSConfig* config;
MMSSettingsSimDataCopy sim_defaults;
};
/* Class */
typedef struct mms_settings_class {
GObjectClass parent;
const MMSSettingsSimData* (*fn_get_sim_data)(
MMSSettings* settings,
const char* imsi);
} MMSSettingsClass;
/* Default values */
#define MMS_SETTINGS_DEFAULT_USER_AGENT "Mozilla/5.0 (Sailfish; Jolla)"
#define MMS_SETTINGS_DEFAULT_SIZE_LIMIT (300*1024)
#define MMS_SETTINGS_DEFAULT_MAX_PIXELS (3000000)
#define MMS_SETTINGS_DEFAULT_ALLOW_DR TRUE
GType mms_settings_get_type(void);
#define MMS_TYPE_SETTINGS (mms_settings_get_type())
#define MMS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
MMS_TYPE_SETTINGS, MMSSettingsClass))
MMSSettings*
mms_settings_ref(
MMSSettings* settings);
void
mms_settings_unref(
MMSSettings* settings);
MMSSettings*
mms_settings_default_new(
const MMSConfig* config);
const MMSSettingsSimData*
mms_settings_get_sim_data(
MMSSettings* settings,
const char* imsi);
void
mms_settings_sim_data_default(
MMSSettingsSimData* data);
void
mms_settings_set_sim_defaults(
MMSSettings* settings,
const MMSSettingsSimData* data);
MMSSettingsSimDataCopy*
mms_settings_sim_data_copy_new(
const MMSSettingsSimData* data);
void
mms_settings_sim_data_copy_free(
MMSSettingsSimDataCopy* data);
#endif /* JOLLA_MMS_SETTINGS_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
...@@ -39,6 +39,7 @@ SOURCES += \ ...@@ -39,6 +39,7 @@ SOURCES += \
src/mms_message.c \ src/mms_message.c \
src/mms_lib_util.c \ src/mms_lib_util.c \
src/mms_log.c \ src/mms_log.c \
src/mms_settings.c \
src/mms_task.c \ src/mms_task.c \
src/mms_task_ack.c \ src/mms_task_ack.c \
src/mms_task_decode.c \ src/mms_task_decode.c \
...@@ -71,4 +72,5 @@ HEADERS += \ ...@@ -71,4 +72,5 @@ HEADERS += \
include/mms_lib_types.h \ include/mms_lib_types.h \
include/mms_lib_util.h \ include/mms_lib_util.h \
include/mms_log.h \ include/mms_log.h \
include/mms_message.h include/mms_message.h \
include/mms_settings.h
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "mms_attachment.h" #include "mms_attachment.h"
#include "mms_file_util.h" #include "mms_file_util.h"
#include "mms_settings.h"
#include "mms_codec.h" #include "mms_codec.h"
#ifdef HAVE_MAGIC #ifdef HAVE_MAGIC
...@@ -344,12 +345,13 @@ mms_attachment_reset( ...@@ -344,12 +345,13 @@ mms_attachment_reset(
gboolean gboolean
mms_attachment_resize( mms_attachment_resize(
MMSAttachment* at) MMSAttachment* at,
const MMSSettingsSimData* settings)
{ {
if (at) { if (at) {
MMSAttachmentClass* klass = MMS_ATTACHMENT_GET_CLASS(at); MMSAttachmentClass* klass = MMS_ATTACHMENT_GET_CLASS(at);
if (klass->fn_resize) { if (klass->fn_resize) {
return klass->fn_resize(at); return klass->fn_resize(at, settings);
} }
} }
return FALSE; return FALSE;
......
...@@ -37,8 +37,11 @@ struct _mms_attachment { ...@@ -37,8 +37,11 @@ struct _mms_attachment {
typedef struct mms_attachment_class { typedef struct mms_attachment_class {
GObjectClass parent; GObjectClass parent;
void (*fn_reset)(MMSAttachment* attachment); void (*fn_reset)(
gboolean (*fn_resize)(MMSAttachment* attachment); MMSAttachment* attachment);
gboolean (*fn_resize)(
MMSAttachment* attachment,
const MMSSettingsSimData* settings);
} MMSAttachmentClass; } MMSAttachmentClass;
GType mms_attachment_get_type(void); GType mms_attachment_get_type(void);
...@@ -80,7 +83,8 @@ mms_attachment_guess_content_type( ...@@ -80,7 +83,8 @@ mms_attachment_guess_content_type(
gboolean gboolean
mms_attachment_resize( mms_attachment_resize(
MMSAttachment* attachment); MMSAttachment* attachment,
const MMSSettingsSimData* settings);
#endif /* JOLLA_MMS_ATTACHMENT_H */ #endif /* JOLLA_MMS_ATTACHMENT_H */
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
*/ */
#include "mms_attachment_image.h" #include "mms_attachment_image.h"
#include "mms_settings.h"
#include "mms_file_util.h" #include "mms_file_util.h"
#ifdef MMS_RESIZE_IMAGEMAGICK #ifdef MMS_RESIZE_IMAGEMAGICK
...@@ -32,13 +33,16 @@ G_DEFINE_TYPE(MMSAttachmentImage, mms_attachment_image, MMS_TYPE_ATTACHMENT); ...@@ -32,13 +33,16 @@ G_DEFINE_TYPE(MMSAttachmentImage, mms_attachment_image, MMS_TYPE_ATTACHMENT);
int int
mms_attachment_image_next_resize_step( mms_attachment_image_next_resize_step(
MMSAttachmentImage* image, MMSAttachmentImage* image,
const MMSSettingsSimData* settings,
unsigned int columns, unsigned int columns,
unsigned int rows) unsigned int rows)
{ {
int next_step = image->resize_step + 1; int next_step = image->resize_step + 1;
if (image->attachment.config->max_pixels > 0) { const unsigned int max_pixels = settings ? settings->max_pixels :
MMS_SETTINGS_DEFAULT_MAX_PIXELS;
if (max_pixels > 0) {
unsigned int size = (columns/(next_step+1))*(rows/(next_step+1)); unsigned int size = (columns/(next_step+1))*(rows/(next_step+1));
while (size > 0 && size > image->attachment.config->max_pixels) { while (size > 0 && size > max_pixels) {
next_step++; next_step++;
size = (columns/(next_step+1))*(rows/(next_step+1)); size = (columns/(next_step+1))*(rows/(next_step+1));
} }
...@@ -70,7 +74,8 @@ mms_attachment_image_prepare_filename( ...@@ -70,7 +74,8 @@ mms_attachment_image_prepare_filename(
static static
gboolean gboolean
mms_attachment_image_resize_default( mms_attachment_image_resize_default(
MMSAttachmentImage* image) MMSAttachmentImage* image,
const MMSSettingsSimData* settings)
{ {
gboolean ok = FALSE; gboolean ok = FALSE;
#ifdef MMS_RESIZE_IMAGEMAGICK #ifdef MMS_RESIZE_IMAGEMAGICK
...@@ -88,7 +93,7 @@ mms_attachment_image_resize_default( ...@@ -88,7 +93,7 @@ mms_attachment_image_resize_default(
const unsigned int src_cols = src->magick_columns; const unsigned int src_cols = src->magick_columns;
const unsigned int src_rows = src->magick_rows; const unsigned int src_rows = src->magick_rows;
const int next_step = mms_attachment_image_next_resize_step(image, const int next_step = mms_attachment_image_next_resize_step(image,
src_cols, src_rows); settings, src_cols, src_rows);
const unsigned int cols = src_cols/(next_step+1); const unsigned int cols = src_cols/(next_step+1);
const unsigned int rows = src_rows/(next_step+1); const unsigned int rows = src_rows/(next_step+1);
Image* dest; Image* dest;
...@@ -119,7 +124,7 @@ mms_attachment_image_resize_default( ...@@ -119,7 +124,7 @@ mms_attachment_image_resize_default(
DestroyImageInfo(info); DestroyImageInfo(info);
#else #else
# ifdef MMS_RESIZE_QT # ifdef MMS_RESIZE_QT
ok = mms_attachment_image_resize_qt(image); ok = mms_attachment_image_resize_qt(image, settings);
# endif /* MMS_RESIZE_QT */ # endif /* MMS_RESIZE_QT */
#endif /* MMS_RESIZE_IMAGEMAGICK */ #endif /* MMS_RESIZE_IMAGEMAGICK */
return ok; return ok;
...@@ -128,7 +133,8 @@ mms_attachment_image_resize_default( ...@@ -128,7 +133,8 @@ mms_attachment_image_resize_default(
static static
gboolean gboolean
mms_attachment_image_resize_type_specific( mms_attachment_image_resize_type_specific(
MMSAttachmentImage* image) MMSAttachmentImage* image,
const MMSSettingsSimData* settings)
{ {
/* If klass->fn_resize_new is not NULL, then we assume that all /* If klass->fn_resize_new is not NULL, then we assume that all
* other callbacks are present as well */ * other callbacks are present as well */
...@@ -141,7 +147,7 @@ mms_attachment_image_resize_type_specific( ...@@ -141,7 +147,7 @@ mms_attachment_image_resize_type_specific(
gboolean can_resize; gboolean can_resize;
const char* fname = mms_attachment_image_prepare_filename(image); const char* fname = mms_attachment_image_prepare_filename(image);
const int next_step = mms_attachment_image_next_resize_step(image, const int next_step = mms_attachment_image_next_resize_step(image,
resize->image.width, resize->image.height); settings, resize->image.width, resize->image.height);
MMSAttachmentImageSize image_size; MMSAttachmentImageSize image_size;
MMSAttachmentImageSize out_size; MMSAttachmentImageSize out_size;
image_size = resize->image; image_size = resize->image;
...@@ -248,7 +254,8 @@ mms_attachment_image_resize_type_specific( ...@@ -248,7 +254,8 @@ mms_attachment_image_resize_type_specific(
static static
gboolean gboolean
mms_attachment_image_resize( mms_attachment_image_resize(
MMSAttachment* at) MMSAttachment* at,
const MMSSettingsSimData* settings)
{ {
MMSAttachmentImage* image = MMS_ATTACHMENT_IMAGE(at); MMSAttachmentImage* image = MMS_ATTACHMENT_IMAGE(at);
gboolean ok; gboolean ok;
...@@ -256,8 +263,8 @@ mms_attachment_image_resize( ...@@ -256,8 +263,8 @@ mms_attachment_image_resize(
g_mapped_file_unref(at->map); g_mapped_file_unref(at->map);
at->map = NULL; at->map = NULL;
}