void UserRecommendation::write() { _map_to_json(); m_time = _get_current_time(); prepared_statement_ptr& insertStmt = UserRecommendation::m_sharedData.m_insertStmtPtr; insertStmt->setString(1, m_user_id); insertStmt->setString(2, m_rec_list); insertStmt->setString(3,m_time); insertStmt->execute(); }
void log(const char *format, ...) { va_list arg_list; char log_text[1024+1] = "LOG: "; int n = 5; n += _get_current_time(log_text+n, 1024-n); va_start (arg_list,format); n += _vsnprintf (log_text+n, 1024-n, format, arg_list); va_end (arg_list); n += _snprintf (log_text+n, 1024-n, "\r\n"); log_text[1024] = '\0'; OutputDebugString (log_text); }
gboolean cd_clock_update_with_time (GldiModuleInstance *myApplet) { CD_APPLET_ENTER; //\________________ On recupere l'heure courante. time_t epoch = (time_t) time (NULL); _get_current_time (epoch, myApplet); //\________________ On change la date si necessaire. int iWidth, iHeight; CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight); gboolean bNewDate = (myData.currentTime.tm_mday != myData.iLastCheckedDay || myData.currentTime.tm_mon != myData.iLastCheckedMonth || myData.currentTime.tm_year != myData.iLastCheckedYear); if (bNewDate) { strftime (s_cDateBuffer, CD_CLOCK_DATE_BUFFER_LENGTH, "%a %d %b", &myData.currentTime); myData.iLastCheckedDay = myData.currentTime.tm_mday; myData.iLastCheckedMonth = myData.currentTime.tm_mon; myData.iLastCheckedYear = myData.currentTime.tm_year; } if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOldStyle && myConfig.iShowDate == CAIRO_DOCK_INFO_ON_ICON) { if (bNewDate || myData.iDateTexture == 0) { if (myData.iDateTexture != 0) _cairo_dock_delete_texture (myData.iDateTexture); double fScale = (double) iWidth / (double) myData.DimensionData.width; GldiTextDescription labelDescription; memset (&labelDescription, 0, sizeof (GldiTextDescription)); gldi_text_description_set_font (&labelDescription, (gchar*)"Sans 8"); // casted and then set to null labelDescription.fColorStart.rgba.red = myConfig.fDateColor[0]; labelDescription.fColorStart.rgba.green = myConfig.fDateColor[1]; labelDescription.fColorStart.rgba.blue = myConfig.fDateColor[2]; labelDescription.fColorStart.rgba.alpha = 1.; labelDescription.bNoDecorations = TRUE; cairo_surface_t *pDateSurface = cairo_dock_create_surface_from_text_full (s_cDateBuffer, &labelDescription, fScale, iWidth, &myData.iDateWidth, &myData.iDateHeight); //g_print ("date : %dx%d\n", myData.iDateWidth, myData.iDateHeight); myData.iDateTexture = cairo_dock_create_texture_from_surface (pDateSurface); cairo_surface_destroy (pDateSurface); labelDescription.cFont = NULL; gldi_text_description_reset (&labelDescription); } } if (bNewDate && myConfig.iShowDate == CAIRO_DOCK_INFO_ON_LABEL) { CD_APPLET_SET_NAME_FOR_MY_ICON (s_cDateBuffer); } //\________________ On dessine avec cette heure. myData.iSmoothAnimationStep = 0; if (myConfig.bOldStyle) { if (CD_APPLET_MY_CONTAINER_IS_OPENGL) cd_clock_render_analogic_to_texture (myApplet, iWidth, iHeight, &myData.currentTime, 0.); else cd_clock_draw_analogic (myApplet, iWidth, iHeight, &myData.currentTime); } else { cd_clock_draw_text (myApplet, iWidth, iHeight, &myData.currentTime); ///if (CD_APPLET_MY_CONTAINER_IS_OPENGL) // on ne sait pas bien dessiner du texte, donc on le fait en cairo, et on transfere tout sur notre texture. /// cairo_dock_update_icon_texture (myIcon); } ///CD_APPLET_REDRAW_MY_ICON; //\________________ On teste les alarmes et les taches. if (!myConfig.bShowSeconds || myData.currentTime.tm_min != myData.iLastCheckedMinute) // un g_timeout de 1min ne s'effectue pas forcement a exectement 1 minute d'intervalle, et donc pourrait "sauter" la minute de l'alarme, d'ou le test sur bShowSeconds dans le cas ou l'applet ne verifie que chaque minute. { myData.iLastCheckedMinute = myData.currentTime.tm_min; // les alarmes. CDClockAlarm *pAlarm; guint i; for (i = 0; i < myConfig.pAlarms->len; i ++) { pAlarm = g_ptr_array_index (myConfig.pAlarms, i); if (myData.currentTime.tm_hour == pAlarm->iHour && myData.currentTime.tm_min == pAlarm->iMinute) { gboolean bShowAlarm = FALSE, bRemoveAlarm = FALSE; if (pAlarm->iDayOfWeek > 0) { if (pAlarm->iDayOfWeek == 1) bShowAlarm = TRUE; else if (pAlarm->iDayOfWeek - 1 == myData.currentTime.tm_wday) bShowAlarm = TRUE; else if (myData.currentTime.tm_wday == 0 || myData.currentTime.tm_wday == 6) // week-end { if (pAlarm->iDayOfWeek == 9) bShowAlarm = TRUE; } else if (pAlarm->iDayOfWeek == 8) bShowAlarm = TRUE; } else if (pAlarm->iDayOfMonth > 0) bShowAlarm = (pAlarm->iDayOfMonth - 1 == myData.currentTime.tm_mday); else // c'est une alarme qui ne se repete pas. { bShowAlarm = TRUE; bRemoveAlarm = TRUE; } if (bShowAlarm) { cd_message ("Dring ! %s", pAlarm->cMessage); gldi_dialog_show_temporary (pAlarm->cMessage, myIcon, myContainer, 60e3); if (pAlarm->cCommand != NULL) { if (myData.iAlarmPID > 0) { kill (myData.iAlarmPID, 1); myData.iAlarmPID = 0; } GError *erreur = NULL; gchar **argv = g_strsplit (pAlarm->cCommand, " ", -1); g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, &myData.iAlarmPID, &erreur); if (erreur != NULL) { cd_warning ("clock : when trying to execute '%s' : %s", pAlarm->cCommand, erreur->message); g_error_free (erreur); myData.iAlarmPID = 0; } g_strfreev (argv); cd_message (" --> child_pid : %d", myData.iAlarmPID); } } if (bRemoveAlarm) { cd_message ("Cette alarme ne sera pas repetee"); g_ptr_array_remove_index (myConfig.pAlarms, i); cd_clock_free_alarm (pAlarm); /// A FAIRE : effacer l'heure dans le fichier de conf pour cette alarme. } } } // display missed tasks. if (!myData.bTaskCheckedOnce) { myData.bTaskCheckedOnce = TRUE; myData.pMissedTasks = cd_clock_get_missed_tasks (myApplet); } if (myData.pMissedTasks != NULL) // so if the dialog was closed before we could acknowledge all the tasks, it will re-open. { CDClockTask *pTask = myData.pMissedTasks->data; gchar *cMessage = _make_missed_task_message (pTask, myApplet); CairoDialogAttr attr; memset (&attr, 0, sizeof (CairoDialogAttr)); attr.cText = cMessage; attr.bUseMarkup = TRUE; attr.cImageFilePath = (gchar *)MY_APPLET_SHARE_DATA_DIR"/icon-task.png"; const gchar *cButtonsImage[3] = {"ok", NULL, NULL}; if (myData.pMissedTasks->next != NULL) { cButtonsImage[0] = "cancel"; cButtonsImage[1] = "next.png"; } attr.cButtonsImage = cButtonsImage; attr.pActionFunc = (CairoDockActionOnAnswerFunc)_on_next_missed_task; attr.pUserData = myApplet; attr.pFreeDataFunc = NULL; attr.iTimeLength = 0; attr.pIcon = myIcon; attr.pContainer = myContainer; gldi_dialog_new (&attr); g_free (cMessage); } // display next task. if (myData.pNextTask != NULL) { //g_print ("next task : %s\n", myData.pNextTask->cTitle); struct tm st; st.tm_min = myData.pNextTask->iMinute; st.tm_hour = myData.pNextTask->iHour; st.tm_mday = myData.pNextTask->iDay; st.tm_mon = myData.pNextTask->iMonth; st.tm_year = myData.pNextTask->iYear - 1900; st.tm_sec = 0; st.tm_isdst = myData.currentTime.tm_isdst; time_t t = mktime (&st); //g_print ("time : %ld, task : %ld\n", epoch, t); if (t < epoch) // la tache est depassee. { // acknowledge this task myData.pNextTask->bAcknowledged = TRUE; myData.pBackend->update_task (myData.pNextTask, myApplet); // look for next task. myData.pNextTask = cd_clock_get_next_scheduled_task (myApplet); } else if (t < epoch + 15*60 && t >= epoch) { if (t < epoch + 60) { if (! myData.pNextTask->bFirstWarning) { //g_print ("first warning\n"); myData.pNextTask->bFirstWarning = TRUE; gchar *cText = g_strdup_printf ("%s\n<b>%s</b>\n %s\n\n%s", D_("It's time for the following task:"), myData.pNextTask->cTitle?myData.pNextTask->cTitle:D_("No title"), myData.pNextTask->cText?myData.pNextTask->cText:"", D_("Repeat this message every:")); _task_warning (myData.pNextTask, cText); g_free (cText); } } else if (! myData.pNextTask->b15mnWarning) { //g_print ("15 mn warning\n"); myData.pNextTask->b15mnWarning = TRUE; gchar *cText = g_strdup_printf ("%s\n<b>%s</b>\n %s", D_("This task will begin in 15 minutes:"), myData.pNextTask->cTitle?myData.pNextTask->cTitle:D_("No title"), myData.pNextTask->cText?myData.pNextTask->cText:""); CairoDialogAttr attr; memset (&attr, 0, sizeof (CairoDialogAttr)); attr.cText = (gchar *)cText; attr.cImageFilePath = (gchar *)MY_APPLET_SHARE_DATA_DIR"/icon-task.png"; attr.iTimeLength = 60e3; attr.bUseMarkup = TRUE; attr.pIcon = myIcon; attr.pContainer = myContainer; gldi_dialog_new (&attr); CD_APPLET_DEMANDS_ATTENTION (NULL, 60); } } // display next anniversary if it is scheduled in less than 1 day, because anniversary require time to prepare. if (myData.pNextAnniversary != NULL) { if (!myData.pNextAnniversary->b1DayWarning && ! myData.pNextAnniversary->bFirstWarning && ! myData.pNextAnniversary->b15mnWarning) { GDate* pCurrentDate = g_date_new_dmy (myData.currentTime.tm_mday, myData.currentTime.tm_mon + 1, myData.currentTime.tm_year+1900); GDate* pAnnivDate = g_date_new_dmy (myData.pNextAnniversary->iDay, myData.pNextAnniversary->iMonth + 1, myData.currentTime.tm_year+1900); gint iDaysToNextAnniversary = g_date_days_between (pCurrentDate, pAnnivDate); if (iDaysToNextAnniversary >= 0 && iDaysToNextAnniversary <= 1) { myData.pNextAnniversary->b1DayWarning = TRUE; gchar *cText = g_strdup_printf ("%s\n<b>%s</b>\n %s\n\n%s", iDaysToNextAnniversary == 0 ? D_("Today is the following anniversary:") : D_("Tomorrow is the following anniversary:"), myData.pNextTask->cTitle?myData.pNextTask->cTitle:D_("No title"), myData.pNextTask->cText?myData.pNextTask->cText:"", D_("Repeat this message every:")); _task_warning (myData.pNextTask, cText); g_free (cText); myData.pNextAnniversary = cd_clock_get_next_anniversary (myApplet); } g_date_free (pCurrentDate); g_date_free (pAnnivDate); } } } } CD_APPLET_LEAVE(TRUE); }
void cd_clock_init_time (GldiModuleInstance *myApplet) { time_t epoch = (time_t) time (NULL); _get_current_time (epoch, myApplet); }