/** * date.c * An extension to GIMP that provides access to some simple date * functions. * * Copyright (c) 2013 Samuel A. Rebelsky. All rights reserved. * * This file is part of The Glimmer Guide to GIMP Plugins (aka GGGP). * * GGGP 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 3 of the License, or * (at your option) any later version. * * GGGP 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 GGGP. If not, see . */ // +---------+--------------------------------------------------------- // | Headers | // +---------+ #include #include #include // +--------+---------------------------------------------------------- // | Macros | // +--------+ /** * Print a string (somewhere). Right now, this prints to stderr, which * means it only works when the program is run from the terminal. */ #define REPORT(str) fprintf (stderr, "*** %s ***\n", str) /** * Print an integer. */ #define REPORT_INT(i) fprintf (stderr, "*** %s: %d ***\n", #i, i) // +--------------------------+---------------------------------------- // | Function Predeclarations | // +--------------------------+ static void query (void); static void run (const gchar *name, gint nparams, const GimpParam *params, gint *nreturn_vals, GimpParam **return_vals); // +-------------+----------------------------------------------------- // | Boilerplate | // +-------------+ /** * The four key functions. This structure *must* be called PLUG_IN_INFO. */ GimpPlugInInfo PLUG_IN_INFO = { NULL, NULL, query, run }; /** * Indicate that we're ready to begin the main part of the code. */ MAIN () // +-------------------------+----------------------------------------- // | Standard GIMP Functions | // +-------------------------+ static void init (void) { } // init static void quit (void) { } // quit static void query (void) { // Build the description of the parameters that the function expects. // Each parameter has a type, a name, and a description // All plug-ins must take a run-mode. Plug-ins associated with an // image static GimpParamDef args[] = { }; // args static GimpParamDef returns[]= { { GIMP_PDB_INT32, "unixtime", "seconds since the epoch" }, { GIMP_PDB_INT32, "year", "year" }, { GIMP_PDB_INT32, "month", "month of the year" }, { GIMP_PDB_INT32, "day", "day of the month" }, { GIMP_PDB_INT32, "hour", "hour of the day" }, { GIMP_PDB_INT32, "minute", "minute of the hour" }, { GIMP_PDB_INT32, "second", "second of the minute" }, }; // returns // Tell the GIMP about our plugin. gimp_install_procedure ( "gggp/date", // Name "Get information on the current date/time", // Blurb "Get information on the current data/time", // Help "Samuel A. Rebelsky", // Author "Copyright (c) Samuel A. Rebelsky. All rights reserved.", // Copyright "2013", // Year "", // Path "", // Image types GIMP_PLUGIN, // Type 0, // Number of params 7, // Number of return vals NULL, // Param descriptions returns // Return descriptions ); } // query static void run (const gchar *name, gint nparams, const GimpParam *params, gint *nreturn_vals, GimpParam **return_vals) { // Prepare status static GimpParam results[8]; results[0].type = GIMP_PDB_STATUS; results[0].data.d_status = GIMP_PDB_SUCCESS; *nreturn_vals = 8; *return_vals = results; // Compute the time info time_t tnow; time (&tnow); struct tm *now = localtime (&tnow); // Fill in the return values results[1].type = GIMP_PDB_INT32; results[1].data.d_int32 = (int) time (NULL); results[2].type = GIMP_PDB_INT32; results[2].data.d_int32 = now->tm_year + 1900; results[3].type = GIMP_PDB_INT32; results[3].data.d_int32 = now->tm_mon + 1; results[4].type = GIMP_PDB_INT32; results[4].data.d_int32 = now->tm_mday; results[5].type = GIMP_PDB_INT32; results[5].data.d_int32 = now->tm_hour; results[6].type = GIMP_PDB_INT32; results[6].data.d_int32 = now->tm_min; results[7].type = GIMP_PDB_INT32; results[7].data.d_int32 = now->tm_sec; } // run