Exemple #1
0
gint orage_days_between(struct tm *t1, struct tm *t2)
{
    GDate *g_t1, *g_t2;
    gint dd;
    g_t1 = g_date_new_dmy(t1->tm_mday, t1->tm_mon, t1->tm_year);
    g_t2 = g_date_new_dmy(t2->tm_mday, t2->tm_mon, t2->tm_year);
    dd = g_date_days_between(g_t1, g_t2);
    g_date_free(g_t1);
    g_date_free(g_t2);
    return(dd);
}
Exemple #2
0
/* GTODO_NO_DUE_DATE = no due date */
gint32 gtodo_todo_item_check_due(GTodoItem *item)
{
	GDate *today;
	int i;
	if(item->due == NULL) return GTODO_NO_DUE_DATE;
	today = g_date_new();
	g_date_set_time_t(today, time(NULL));
	i = g_date_days_between(item->due,today);
	g_date_free(today);
	return i;
}
Exemple #3
0
time_t
mrp_time2_get_epoch (MrpTime *t)
{
    GDate  date;
    time_t epoch;

    g_date_set_dmy (&date, 1, 1, 1970);

    epoch = SECS_IN_DAY * g_date_days_between (&date, &t->date);

    epoch += t->hour * SECS_IN_HOUR + t->min * SECS_IN_MIN + t->sec;

    return epoch;
}
Exemple #4
0
static int get_date_offset( GtkCalendar* calendar )
{
    /* FIXME: I think we need a better implementation for this */
    GDate* date;
    GDate* today;
    int y, m, d, offset;
    time_t timeval = time(NULL);
    struct tm* lt = localtime( &timeval );

    gtk_calendar_get_date( calendar, &y, &m, &d );

    date = g_date_new_dmy( d, m, y );
    today = g_date_new_dmy( lt->tm_mday, lt->tm_mon, lt->tm_year+1900 );

    offset = g_date_days_between( date, today );

    g_date_free(date);
    g_date_free(today);
    return ABS(offset);
}
Exemple #5
0
/* This is the only real algorithm related to recurrences.  It goes:
   Step 1) Go forward one period from the reference date.
   Step 2) Back up to align to the phase of the start date.
*/
void
recurrenceNextInstance(const Recurrence *r, const GDate *ref, GDate *next)
{
    PeriodType pt;
    const GDate *start;
    guint mult;
    WeekendAdjust wadj;

    g_return_if_fail(r);
    g_return_if_fail(ref);
    g_return_if_fail(g_date_valid(&r->start));
    g_return_if_fail(g_date_valid(ref));

    /* If the ref date comes before the start date then the next
       occurrence is always the start date, and we're done. */
    start = &r->start;
    if (g_date_compare(ref, start) < 0)
    {
        g_date_set_julian(next, g_date_get_julian(start));
        return;
    }
    g_date_set_julian(next, g_date_get_julian(ref)); /* start at refDate */

    /* Step 1: move FORWARD one period, passing exactly one occurrence. */
    mult = r->mult;
    pt = r->ptype;
    wadj = r->wadj;
    switch (pt)
    {
    case PERIOD_YEAR:
        mult *= 12;
        /* fall through */
    case PERIOD_MONTH:
    case PERIOD_NTH_WEEKDAY:
    case PERIOD_LAST_WEEKDAY:
    case PERIOD_END_OF_MONTH:
        /* Takes care of short months. */
        if (r->wadj == WEEKEND_ADJ_BACK &&
                (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) &&
                (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY))
        {
            /* Allows the following Friday-based calculations to proceed if 'next'
               is between Friday and the target day. */
            g_date_subtract_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 1 : 2);
        }
        if (r->wadj == WEEKEND_ADJ_BACK &&
                (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) &&
                g_date_get_weekday(next) == G_DATE_FRIDAY)
        {
            GDate tmp_sat;
            GDate tmp_sun;
            g_date_set_julian(&tmp_sat, g_date_get_julian(next));
            g_date_set_julian(&tmp_sun, g_date_get_julian(next));
            g_date_add_days(&tmp_sat, 1);
            g_date_add_days(&tmp_sun, 2);

            if (pt == PERIOD_END_OF_MONTH)
            {
                if (g_date_is_last_of_month(next) ||
                        g_date_is_last_of_month(&tmp_sat) ||
                        g_date_is_last_of_month(&tmp_sun))
                    g_date_add_months(next, mult);
                else
                    /* one fewer month fwd because of the occurrence in this month */
                    g_date_add_months(next, mult - 1);
            }
            else
            {
                if (g_date_get_day(&tmp_sat) == g_date_get_day(start))
                {
                    g_date_add_days(next, 1);
                    g_date_add_months(next, mult);
                }
                else if (g_date_get_day(&tmp_sun) == g_date_get_day(start))
                {
                    g_date_add_days(next, 2);
                    g_date_add_months(next, mult);
                }
                else if (g_date_get_day(next) >= g_date_get_day(start))
                {
                    g_date_add_months(next, mult);
                }
                else if (g_date_is_last_of_month(next))
                {
                    g_date_add_months(next, mult);
                }
                else if (g_date_is_last_of_month(&tmp_sat))
                {
                    g_date_add_days(next, 1);
                    g_date_add_months(next, mult);
                }
                else if (g_date_is_last_of_month(&tmp_sun))
                {
                    g_date_add_days(next, 2);
                    g_date_add_months(next, mult);
                }
                else
                {
                    /* one fewer month fwd because of the occurrence in this month */
                    g_date_add_months(next, mult - 1);
                }
            }
        }
        else if ( g_date_is_last_of_month(next) ||
                  ((pt == PERIOD_MONTH || pt == PERIOD_YEAR) &&
                   g_date_get_day(next) >= g_date_get_day(start)) ||
                  ((pt == PERIOD_NTH_WEEKDAY || pt == PERIOD_LAST_WEEKDAY) &&
                   nth_weekday_compare(start, next, pt) <= 0) )
            g_date_add_months(next, mult);
        else
            /* one fewer month fwd because of the occurrence in this month */
            g_date_add_months(next, mult - 1);
        break;
    case PERIOD_WEEK:
        mult *= 7;
        /* fall through */
    case PERIOD_DAY:
        g_date_add_days(next, mult);
        break;
    case PERIOD_ONCE:
        g_date_clear(next, 1);  /* We already caught the case where ref is */
        return;                 /* earlier than start, so this is invalid. */
    default:
        PERR("Invalid period type");
        break;
    }

    /* Step 2: Back up to align to the base phase. To ensure forward
       progress, we never subtract as much as we added (x % mult < mult). */
    switch (pt)
    {
    case PERIOD_YEAR:
    case PERIOD_MONTH:
    case PERIOD_NTH_WEEKDAY:
    case PERIOD_LAST_WEEKDAY:
    case PERIOD_END_OF_MONTH:
    {
        guint dim, n_months;

        n_months = 12 * (g_date_get_year(next) - g_date_get_year(start)) +
                   (g_date_get_month(next) - g_date_get_month(start));
        g_date_subtract_months(next, n_months % mult);

        /* Ok, now we're in the right month, so we just have to align
           the day in one of the three possible ways. */
        dim = g_date_get_days_in_month(g_date_get_month(next),
                                       g_date_get_year(next));
        if (pt == PERIOD_LAST_WEEKDAY || pt == PERIOD_NTH_WEEKDAY)
        {
            gint wdresult = nth_weekday_compare(start, next, pt);
            if (wdresult < 0)
            {
                wdresult = -wdresult;
                g_date_subtract_days(next, wdresult);
            }
            else
                g_date_add_days(next, wdresult);
        }
        else if (pt == PERIOD_END_OF_MONTH || g_date_get_day(start) >= dim)
            g_date_set_day(next, dim);  /* last day in the month */
        else
            g_date_set_day(next, g_date_get_day(start)); /*same day as start*/

        /* Adjust for dates on the weekend. */
        if (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH)
        {
            if (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY)
            {
                switch (wadj)
                {
                case WEEKEND_ADJ_BACK:
                    g_date_subtract_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 1 : 2);
                    break;
                case WEEKEND_ADJ_FORWARD:
                    g_date_add_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 2 : 1);
                    break;
                case WEEKEND_ADJ_NONE:
                default:
                    break;
                }
            }
        }

    }
    break;
    case PERIOD_WEEK:
    case PERIOD_DAY:
        g_date_subtract_days(next, g_date_days_between(start, next) % mult);
        break;
    default:
        PERR("Invalid period type");
        break;
    }
}
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);
}
Exemple #7
0
void
contacts_create_birthdays_window (GUI *appGUI)
{
GtkWidget           *vbox1;
GtkWidget           *hseparator;
GtkWidget           *hbuttonbox;
GtkWidget           *close_button;
GtkTreeViewColumn   *column;
GtkCellRenderer     *renderer;
GtkWidget           *scrolledwindow;
gint i, n, id, age;
guint32 date;
gchar *text, buffer[BUFFER_SIZE], buff[BUFFER_SIZE];
GtkTreeIter iter, n_iter;
GDate *cdate_birthday, *cdate_current;
guint b_day, b_month, b_year;
guint c_day, c_month, c_year;
gboolean flag, leap;

	cdate_birthday = g_date_new ();
	g_return_if_fail (cdate_birthday != NULL);

	cdate_current = g_date_new ();
	g_return_if_fail (cdate_current != NULL);

	i = n = 0;
	while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, NULL, i++)) {
		gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_BIRTH_DAY_DATE, &date, -1);
		if (date) n++;
	}

	if (n == 0) {
		gui_create_dialog (GTK_MESSAGE_INFO, _("No birthdays defined"), GTK_WINDOW (appGUI->main_window));
		return;
	}

	appGUI->cnt->birthdays_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (appGUI->cnt->birthdays_window), _("Birthdays list"));
	gtk_window_set_position (GTK_WINDOW (appGUI->cnt->birthdays_window), GTK_WIN_POS_CENTER_ON_PARENT);
	gtk_window_set_default_size (GTK_WINDOW (appGUI->cnt->birthdays_window), 
                                 config.contacts_birthdays_win_w, config.contacts_birthdays_win_h);
	gtk_window_set_modal (GTK_WINDOW (appGUI->cnt->birthdays_window), TRUE);
	g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_window), "delete_event",
	                  G_CALLBACK (birthdays_window_close_cb), appGUI);
	gtk_window_set_transient_for (GTK_WINDOW (appGUI->cnt->birthdays_window), GTK_WINDOW (appGUI->main_window));
	gtk_container_set_border_width (GTK_CONTAINER (appGUI->cnt->birthdays_window), 8);
	g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_window), "key_press_event",
	                  G_CALLBACK (birthdays_key_press_cb), appGUI);

	vbox1 = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox1);
	gtk_container_add (GTK_CONTAINER (appGUI->cnt->birthdays_window), vbox1);

	scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (scrolledwindow);
	gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow, TRUE, TRUE, 0);

	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	appGUI->cnt->birthdays_list_store = gtk_list_store_new (BIRTHDAYS_NUM_COLUMNS,
	                                                        G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING,
	                                                        G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);

	appGUI->cnt->birthdays_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (appGUI->cnt->birthdays_list_store));
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), config.contacts_rules_hint);
	gtk_widget_show (appGUI->cnt->birthdays_list);
	GTK_WIDGET_SET_FLAGS (appGUI->cnt->birthdays_list, GTK_CAN_DEFAULT);
	gtk_container_add (GTK_CONTAINER (scrolledwindow), appGUI->cnt->birthdays_list);

	appGUI->cnt->birthdays_list_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (appGUI->cnt->birthdays_list));

	g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_list), "button_press_event",
	                  G_CALLBACK (birthdays_list_dbclick_cb), appGUI);

	/* create columns */
	renderer = gtk_cell_renderer_text_new ();
	g_object_set (G_OBJECT (renderer), "xpad", 8, NULL);
	column = gtk_tree_view_column_new_with_attributes (_("Name"), renderer, "text", B_COLUMN_NAME, NULL);
	gtk_tree_view_column_set_visible (column, TRUE);
	gtk_tree_view_column_set_expand (column, TRUE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);
	gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_NAME);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("Days to birthday"), renderer, "text", B_COLUMN_DAYS_NUM, NULL);
	gtk_tree_view_column_set_visible (column, FALSE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	renderer = gtk_cell_renderer_text_new ();
	g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
	g_object_set (G_OBJECT (renderer), "xpad", 8, NULL);
	column = gtk_tree_view_column_new_with_attributes (_("Days to birthday"), renderer, "text", B_COLUMN_DAYS, NULL);
	gtk_tree_view_column_set_visible (column, TRUE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);
	gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_DAYS_NUM);
	g_signal_emit_by_name (column, "clicked");

	column = gtk_tree_view_column_new_with_attributes (_("Age"), renderer, "text", B_COLUMN_AGE, NULL);
	gtk_tree_view_column_set_visible (column, config.visible_age_column);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);
	gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_AGE);

	column = gtk_tree_view_column_new_with_attributes (_("Birthday date"), renderer, "text", B_COLUMN_DATE, NULL);
	gtk_tree_view_column_set_visible (column, config.visible_birthday_date_column);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("Zodiac sign"), renderer, "text", B_COLUMN_ZODIAC, NULL);
	gtk_tree_view_column_set_visible (column, config.visible_zodiac_sign_column);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("ID", renderer, "text", B_COLUMN_ID, NULL);
	gtk_tree_view_column_set_visible (column, FALSE);
	gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column);

	gtk_tree_view_set_enable_search (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), FALSE);

	i = 0;

	g_date_set_julian (cdate_current, utl_get_current_julian ());
	c_day = g_date_get_day (cdate_current);
	c_month = g_date_get_month (cdate_current);
	c_year = g_date_get_year (cdate_current);

	while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, NULL, i++)) {
		gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_BIRTH_DAY_DATE, &date, -1);

		if (g_date_valid_julian (date)) {

			/* calculate age */
			g_date_set_julian (cdate_birthday, date);
			b_day = g_date_get_day (cdate_birthday);
			b_month = g_date_get_month (cdate_birthday);
			b_year = g_date_get_year (cdate_birthday);

			age = (gint) c_year - b_year;
			if (b_month < c_month || (b_month == c_month && b_day < c_day)) age++;

			if (age < 1) continue;

			/* name */
			flag = FALSE;
			g_snprintf (buff, BUFFER_SIZE, "(%s)", _("None"));

			gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_LAST_NAME, &text, -1);
			if (text != NULL) {
				flag = TRUE;
				if (strcmp (text, buff) == 0) {
					text[0] = '\0';
					flag = FALSE;
				}
				g_strlcpy (buffer, text, BUFFER_SIZE);
				g_free (text);
			}

			gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_FIRST_NAME, &text, -1);
			if (text != NULL) {
				if (strcmp (text, buff) == 0) {
					text[0] = '\0';
				}
				if (flag == TRUE) {
					g_strlcat (buffer, " ", BUFFER_SIZE);
					g_strlcat (buffer, text, BUFFER_SIZE);
				} else {
					g_strlcpy (buffer, text, BUFFER_SIZE);
				}
				g_free (text);
			}

			gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_ID, &id, -1);
			gtk_list_store_append (appGUI->cnt->birthdays_list_store, &n_iter);
			gtk_list_store_set (appGUI->cnt->birthdays_list_store, &n_iter,
			                    B_COLUMN_ID, id, B_COLUMN_NAME, buffer, B_COLUMN_AGE, age, -1);

			/* calculate days to birthday */
			b_year = c_year;
			if ((b_month < c_month) || (b_month == c_month && b_day < c_day)) b_year++;

			leap = FALSE;
			if (g_date_valid_dmy (b_day, b_month, b_year) == FALSE) {
				g_date_set_day (cdate_birthday, b_day - 1);
				leap = TRUE;
			}
			g_date_set_year (cdate_birthday, b_year);

			date = g_date_days_between (cdate_current, cdate_birthday);
			if (date == 0) {
				g_snprintf (buffer, BUFFER_SIZE, "%s", _("today"));
			} else {
				g_snprintf (buffer, BUFFER_SIZE, leap ? "%d + 1" : "%d", date);
			}

			g_date_strftime (buff, BUFFER_SIZE, "%A, ", cdate_birthday);
			g_strlcat (buff, julian_to_str (g_date_get_julian (cdate_birthday), config.date_format), BUFFER_SIZE);

			gtk_list_store_set (appGUI->cnt->birthdays_list_store, &n_iter,
			                    B_COLUMN_DAYS_NUM, date, B_COLUMN_DAYS, buffer,
			                    B_COLUMN_DATE, buff, B_COLUMN_ZODIAC, utl_get_zodiac_name (b_day, b_month), -1);
		}

	}
	g_date_free (cdate_birthday);
	g_date_free (cdate_current);

	hseparator = gtk_hseparator_new ();
	gtk_widget_show (hseparator);
	gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 4);

	hbuttonbox = gtk_hbutton_box_new ();
	gtk_widget_show (hbuttonbox);
	gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox, FALSE, TRUE, 0);
	gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
	gtk_box_set_spacing (GTK_BOX (hbuttonbox), 4);

	if (config.default_stock_icons) {
		close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
	} else {
		close_button = gtk_button_new_from_stock (OSMO_STOCK_BUTTON_CLOSE);
	}
	gtk_widget_show (close_button);
	g_signal_connect (close_button, "clicked", G_CALLBACK (button_birthdays_window_close_cb), appGUI);
	gtk_container_add (GTK_CONTAINER (hbuttonbox), close_button);

	gtk_widget_show (appGUI->cnt->birthdays_window);
	gtk_widget_grab_focus (close_button);
}
Exemple #8
0
static struct stats_record *process_file(struct stats_iter *iter,
					struct stats_file *temp_file,
					struct stats_record *cur,
					GDate *date_change_step_size,
					int account_period_offset)
{
	struct stats_record *home, *roaming;
	struct stats_record *next;

	home = NULL;
	roaming = NULL;

	if (!cur)
		cur = get_next_record(iter);
	next = get_next_record(iter);

	while (next) {
		GDate date_cur;
		GDate date_next;
		int append;

		append = FALSE;

		if (cur->roaming)
			roaming = cur;
		else
			home = cur;

		g_date_set_time_t(&date_cur, cur->ts);
		g_date_set_time_t(&date_next, next->ts);

		if (g_date_compare(&date_cur, date_change_step_size) < 0) {
			/* month period size */
			GDateDay day_cur, day_next;
			GDateMonth month_cur, month_next;

			month_cur = g_date_get_month(&date_cur);
			month_next = g_date_get_month(&date_next);

			day_cur = g_date_get_day(&date_cur);
			day_next = g_date_get_day(&date_next);

			if (day_cur == day_next && month_cur != month_next)
				append = TRUE;
			else if (day_cur < account_period_offset
					&& day_next >= account_period_offset)
				append = TRUE;
		} else {
			/* day period size */
			if (g_date_days_between(&date_cur, &date_next) > 0)
				append = TRUE;
		}

		if (append) {
			if (home) {
				append_record(temp_file, home);
				home = NULL;
			}

			if (roaming) {
				append_record(temp_file, roaming);
				roaming = NULL;
			}
		}

		cur = next;
		next = get_next_record(iter);
	}

	return cur;
}
Exemple #9
0
static void
load_chain (PatrolDialogWindow *self, PatrolDialogRecord *r,
            guint idx, GtkWidget *container)
{
    /* build tree model */
    GtkTreeStore *tree_store = gtk_tree_store_new(COLS_NUM, G_TYPE_STRING,
                                                  G_TYPE_BOOLEAN, G_TYPE_INT,
                                                  G_TYPE_POINTER, G_TYPE_POINTER);

    GtkTreeIter *parent = NULL, iter;
    gint i, num_certs = gcr_certificate_chain_get_length(r->chain);
    GcrCertificate *cert = NULL;

    for (i = num_certs - 1; i >= 0; i--) {
        cert = gcr_certificate_chain_get_certificate(r->chain, i);
        gchar *label = gcr_certificate_get_subject_name(cert);

        gtk_tree_store_append(tree_store, &iter, parent);
        gtk_tree_store_set(tree_store, &iter,
                           COL_NAME, label,
                           COL_PIN, i == r->pin_level,
                           COL_PIN_LEVEL, i,
                           COL_CERT, cert,
                           COL_REC, r,
                           -1);
        parent = &iter;
        g_free(label);
    }

    /* set hierarchy title */
    GtkWidget *title_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_box_pack_start(GTK_BOX(container), title_box, FALSE, FALSE, 0);
    gchar *text, *str;
    GtkWidget *label = gtk_label_new(NULL);
    GtkWidget *value;

    if (idx == 0) {
        switch (self->pv->result) {
        case  PATROL_VERIFY_NEW:
        case  PATROL_VERIFY_CHANGE:
            text = g_strdup_printf("<b>%s</b>", _("New Certificate"));
            break;
        case  PATROL_VERIFY_REJECT:
            text = g_strdup_printf("<b>%s</b>", _("Rejected Certificate"));
            break;
        default:
            text = g_strdup_printf("<b>%s</b>", _("Selected Certificate"));
            break;
        }
    } else {
        text = g_strdup_printf("<b>%s #%d</b>", _("Stored Certificate"), idx);
        gtk_widget_set_margin_bottom(GTK_WIDGET(label), 2);
    }

    gtk_label_set_markup(GTK_LABEL(label), text);
    g_free(text);
    gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
    gtk_box_pack_start(GTK_BOX(title_box), label, FALSE, FALSE, 0);

    GtkWidget *grid = gtk_grid_new();
    gtk_widget_set_margin_left(GTK_WIDGET(grid), 5);
    gtk_box_pack_start(GTK_BOX(title_box), grid, FALSE, FALSE, 0);

    label = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(label), _("Seen: "));
    str = g_strdup_printf("%" G_GINT64_FORMAT, r->rec.count_seen);
    text = g_strdup_printf(g_dngettext(textdomain(NULL),
                                       "%s time", "%s times",
                                       r->rec.count_seen), str);
    g_free(str);
    value = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(value), text);
    g_free(text);
    gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
    gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
    gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), value, 1, 0, 1, 1);

    label = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(label), _("First seen: "));
    GDateTime *dtime = g_date_time_new_from_unix_local(r->rec.first_seen);
    text = g_date_time_format(dtime, "%c");
    g_date_time_unref(dtime);
    value = gtk_label_new(NULL);
    gtk_label_set_text(GTK_LABEL(value), text);
    g_free(text);
    gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
    gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
    gtk_grid_attach(GTK_GRID(grid), label, 0, 1, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), value, 1, 1, 1, 1);

    if (r->rec.first_seen != r->rec.last_seen) {
        label = gtk_label_new(NULL);
        gtk_label_set_text(GTK_LABEL(label), _("Last seen: "));
        dtime = g_date_time_new_from_unix_local(r->rec.last_seen);
        text = g_date_time_format(dtime, "%c");
        g_date_time_unref(dtime);
        value = gtk_label_new(NULL);
        gtk_label_set_text(GTK_LABEL(value), text);
        g_free(text);
        gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
        gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
        gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1);
        gtk_grid_attach(GTK_GRID(grid), value, 1, 2, 1, 1);
    }

    if (cert) {
        label = gtk_label_new(NULL);
        gtk_label_set_text(GTK_LABEL(label), _("Validity: "));

        GDate *expiry = gcr_certificate_get_expiry_date(cert);
        GDate *now = g_date_new();
        g_date_set_time_t(now, time(NULL));
        gint diff = g_date_days_between(now, expiry);
        g_date_free(now);
        g_date_free(expiry);

        if (diff > 0) {
            text = g_strdup_printf(g_dngettext(textdomain(NULL),
                                               "Certificate is valid for %d more day",
                                               "Certificate is valid for %d more days",
                                               diff), diff);
        } else if (diff < 0) {
            diff = abs(diff);
            text = g_strdup_printf(g_dngettext(textdomain(NULL),
                                               "Certificate <b>expired</b> %d day ago",
                                               "Certificate <b>expired</b> %d days ago",
                                               diff), diff);
        } else {
            text = g_strdup_printf("Certificate expires today");
        }

        value = gtk_label_new(NULL);
        gtk_label_set_markup(GTK_LABEL(value), text);
        g_free(text);

        gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
        gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START);
        gtk_grid_attach(GTK_GRID(grid), label, 0, 3, 1, 1);
        gtk_grid_attach(GTK_GRID(grid), value, 1, 3, 1, 1);
    }

    gtk_widget_show_all(title_box);

    /* build tree view */
    GtkWidget *tree_view;
    tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
    gtk_tree_view_expand_all(GTK_TREE_VIEW(tree_view));
    gtk_box_pack_start(GTK_BOX(container), tree_view, FALSE, FALSE, 0);
    gtk_widget_show(tree_view);

    g_signal_connect(tree_view, "focus-in-event",
                     G_CALLBACK(on_tree_view_focus), self);
    g_signal_connect(self->pv->renderer, "data-changed",
                     G_CALLBACK(on_cert_changed), tree_view);
    GtkTreeSelection *tree_sel
        = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
    g_signal_connect(tree_sel, "changed", 
                     G_CALLBACK(on_tree_selection_changed), self);

    if (idx == 0) // new chain
        gtk_tree_selection_select_iter(tree_sel, &iter);

    /* first column */
    GtkCellRenderer *tree_renderer = gtk_cell_renderer_text_new();
    GtkTreeViewColumn *tree_column
        = gtk_tree_view_column_new_with_attributes(_("Certificate Hierarchy"),
                                                   tree_renderer, "text",
                                                   COL_NAME, NULL);
    gtk_tree_view_column_set_expand (tree_column, TRUE);
    gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view), tree_column, -1);

    /* second column */
    GtkCellRenderer *toggle_renderer = gtk_cell_renderer_toggle_new();
    g_signal_connect(toggle_renderer, "toggled",
                     G_CALLBACK(on_radio_toggled), tree_store);
    gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(toggle_renderer),
                                       TRUE);

    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view), -1,
                                                _("Pin"), toggle_renderer,
                                                "active", COL_PIN, NULL);
    g_object_unref(tree_store);
}
gboolean
e_reap_trash_directory_sync (GFile *trash_directory,
                             gint expiry_in_days,
                             GCancellable *cancellable,
                             GError **error)
{
	GFileEnumerator *file_enumerator;
	GQueue directories = G_QUEUE_INIT;
	GFile *reaping_directory;
	GFileInfo *file_info;
	const gchar *attributes;
	gboolean success = TRUE;
	GError *local_error = NULL;

	g_return_val_if_fail (G_IS_FILE (trash_directory), FALSE);
	g_return_val_if_fail (expiry_in_days > 0, FALSE);

	reaping_directory = g_file_get_child (
		trash_directory, REAPING_DIRECTORY_NAME);

	attributes =
		G_FILE_ATTRIBUTE_STANDARD_NAME ","
		G_FILE_ATTRIBUTE_STANDARD_TYPE ","
		G_FILE_ATTRIBUTE_TIME_MODIFIED;

	file_enumerator = g_file_enumerate_children (
		trash_directory, attributes,
		G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
		cancellable, error);

	if (file_enumerator == NULL)
		return FALSE;

	file_info = g_file_enumerator_next_file (
		file_enumerator, cancellable, &local_error);

	while (file_info != NULL) {
		GFileType file_type;
		GTimeVal mtime;
		GDate *date_now;
		GDate *date_mtime;
		const gchar *name;
		gboolean reap_it;
		gint days_old;

		name = g_file_info_get_name (file_info);
		file_type = g_file_info_get_file_type (file_info);
		g_file_info_get_modification_time (file_info, &mtime);

		/* Calculate how many days ago the file was modified. */
		date_now = g_date_new ();
		g_date_set_time_t (date_now, time (NULL));
		date_mtime = g_date_new ();
		g_date_set_time_val (date_mtime, &mtime);
		days_old = g_date_days_between (date_mtime, date_now);
		g_date_free (date_mtime);
		g_date_free (date_now);

		reap_it =
			(file_type == G_FILE_TYPE_DIRECTORY) &&
			(days_old >= expiry_in_days);

		if (reap_it) {
			GFile *child;

			child = g_file_get_child (trash_directory, name);

			/* If we find an unfinished reaping directory, put
			 * it on the head of the queue so we reap it first. */
			if (g_file_equal (child, reaping_directory))
				g_queue_push_head (&directories, child);
			else
				g_queue_push_tail (&directories, child);
		}

		g_object_unref (file_info);

		file_info = g_file_enumerator_next_file (
			file_enumerator, cancellable, &local_error);
	}

	if (local_error != NULL) {
		g_propagate_error (error, local_error);
		success = FALSE;
	}

	g_object_unref (file_enumerator);

	/* Now delete the directories we've queued up. */
	while (success && !g_queue_is_empty (&directories)) {
		GFile *directory;

		directory = g_queue_pop_head (&directories);

		/* First we rename the directory to prevent it
		 * from being recovered while being deleted. */
		if (!g_file_equal (directory, reaping_directory))
			success = g_file_move (
				directory, reaping_directory,
				G_FILE_COPY_NONE, cancellable,
				NULL, NULL, error);

		if (success)
			success = e_file_recursive_delete_sync (
				reaping_directory, cancellable, error);

		g_object_unref (directory);
	}

	/* Flush the queue in case we aborted on an error. */
	while (!g_queue_is_empty (&directories))
		g_object_unref (g_queue_pop_head (&directories));

	g_object_unref (reaping_directory);

	return success;
}