about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMarco Peereboom <marco@conformal.com>2010-12-26 15:04:40 +0000
committerMarco Peereboom <marco@conformal.com>2010-12-26 15:04:40 +0000
commitb7a81e74d0154eb460e90873fc3822897558ef38 (patch)
tree0c0489e29e6d552f1edd96ec2700a1e95e04d2b0
parent53c724480da724b46d54809689171646bda3c43a (diff)
downloadxombrero-b7a81e74d0154eb460e90873fc3822897558ef38.tar.gz
Add save tab support.
fix boneheaded typo from edd

Sligthly modified diff from Stevan Andjelkovic <stevan@student.chalmers.se>
-rw-r--r--xxxterm.110
-rw-r--r--xxxterm.c77
2 files changed, 86 insertions, 1 deletions
diff --git a/xxxterm.1 b/xxxterm.1
index 9f6bfdf..9aa97af 100644
--- a/xxxterm.1
+++ b/xxxterm.1
@@ -287,6 +287,16 @@ The commands and descriptions are listed below:
 .It Cm qa, qa!, q!
 Quit
 .Nm
+.It Cm w
+Save open tabs.
+The tabs will be restored next time
+.Nm
+is started.
+.It Cm wq, wq!
+Save open tabs and quit.
+The tabs will be restored next time
+.Nm
+is started.
 .It Cm fav
 Show favorites
 .It Cm favadd
diff --git a/xxxterm.c b/xxxterm.c
index 0c636ba..c2eaab2 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -210,6 +210,7 @@ struct karg {
 #define XT_DIR			(".xxxterm")
 #define XT_CONF_FILE		("xxxterm.conf")
 #define XT_FAVS_FILE		("favorites")
+#define XT_SAVED_TABS_FILE	("saved_tabs")
 #define XT_CB_HANDLED		(TRUE)
 #define XT_CB_PASSTHROUGH	(FALSE)
 #define XT_DOCTYPE		"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
@@ -952,6 +953,75 @@ quit(struct tab *t, struct karg *args)
 }
 
 int
+restore_saved_tabs(void)
+{
+	char		file[PATH_MAX];
+	FILE		*f;
+	char		*line = NULL;
+	size_t		linelen;
+	int		empty_saved_tabs_file = 1;
+
+	snprintf(file, sizeof file, "%s/%s/%s",
+	    pwd->pw_dir, XT_DIR, XT_SAVED_TABS_FILE);
+
+	if ((f = fopen(file, "r")) == NULL)
+		return (empty_saved_tabs_file);
+
+	while (!feof(f)) {
+		line = fparseln(f, &linelen, NULL, NULL, 0);
+		if (line) {
+			create_new_tab(line, 1);
+			empty_saved_tabs_file = 0;
+		}
+		free(line);
+		line = NULL;
+	}
+
+	fclose(f);
+	/*remove(file);*/
+
+	return (empty_saved_tabs_file);
+}
+
+int
+save_tabs(struct tab *t, struct karg *args)
+{
+	char			file[PATH_MAX];
+	FILE			*f;
+	struct tab		*ti;
+	WebKitWebFrame		*frame;
+	const gchar		*uri;
+
+	snprintf(file, sizeof file, "%s/%s/%s",
+	    pwd->pw_dir, XT_DIR, XT_SAVED_TABS_FILE);
+
+	if ((f = fopen(file, "w")) == NULL) {
+		warn("save_tabs_and_quit");
+		return (1);
+	}
+
+	TAILQ_FOREACH(ti, &tabs, entry) {
+		frame = webkit_web_view_get_main_frame(ti->wv);
+		uri = webkit_web_frame_get_uri(frame);
+		if (uri)
+			fprintf(f, "%s\n", uri);
+	}
+
+	fclose(f);
+
+	return (0);
+}
+
+int
+save_tabs_and_quit(struct tab *t, struct karg *args)
+{
+	save_tabs(t, NULL);
+	quit(t, NULL);
+
+	return (1);
+}
+
+int
 toggle_js(struct tab *t, struct karg *args)
 {
 	int			es, i;
@@ -1141,7 +1211,7 @@ xtp_page_fl(struct tab *t, struct karg *args)
 	t->xtp_meaning = XT_XTP_TAB_MEANING_FL;
 
 	/* new session key */
-	if (!update_favorite_tabs)
+	if (!updating_fl_tabs)
 		generate_xtp_session_key(&fl_session_key);
 
 	/* open favorites */
@@ -2239,6 +2309,9 @@ struct cmd {
 	{ "q!",			0,	quit,			{0} },
 	{ "qa",			0,	quit,			{0} },
 	{ "qa!",		0,	quit,			{0} },
+	{ "w",			0,	save_tabs,		{0} },
+	{ "wq",			0,	save_tabs_and_quit,	{0} },
+	{ "wq!",		0,	save_tabs_and_quit,	{0} },
 	{ "help",		0,	help,			{0} },
 	{ "about",		0,	about,			{0} },
 	{ "stats",		0,	stats,			{0} },
@@ -3930,6 +4003,8 @@ main(int argc, char *argv[])
 
 	create_canvas();
 
+	focus = restore_saved_tabs();
+
 	while (argc) {
 		create_new_tab(argv[0], focus);
 		focus = 0;
>301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597